Skip to content

bazel coverage failed due to "No source for code" #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nlou9 opened this issue May 9, 2023 · 5 comments
Closed

bazel coverage failed due to "No source for code" #1217

nlou9 opened this issue May 9, 2023 · 5 comments
Labels
Can Close? Will close in 30 days if there is no new activity

Comments

@nlou9
Copy link

nlou9 commented May 9, 2023

🐞 bug report

Affected Rule

bazel coverage

The issue is caused by the rule:

Is this a regression?

Not sure

Description

bazel test passed and bazel coverage failed.
We use pytest tmpdir to create temporary directory for one of the test cases during execution and it is assumed to be removed after the test cases finished automatically. It seems bazel coverage is trying to find the source file for the files in temporary directory which it shouldn't. It will throw "no source file found" error and this prevents generating coverage report.

Also, Is there a workaround to ignore "no source for code" error?

bazel coverage  --instrument_test_targets=false --test_output=streamed --verbose_failures --action_env=VERBOSE_COVERAGE=true --sandbox_debug --java_runtime_version=remotejdk_11
 //:common_tools_test

Logs:

INFO: Invocation ID: eed41e0b-978a-4c79-8437-16ddaceb1224
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
INFO: Using default value for --instrumentation_filter: "^//".
INFO: Override the above default with --instrumentation_filter
INFO: Analyzed target //:common_tools_test (1 packages loaded, 20 targets configured).
INFO: Found 1 test target...
+ [[ -z bazel-out/darwin-fastbuild/bin/common_tools_test.instrumented_files ]]
+ export ROOT=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__
+ ROOT=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__
+ [[ bazel-out/darwin-fastbuild/bin/common_tools_test.instrumented_files != /* ]]
+ export COVERAGE_MANIFEST=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.instrumented_files
+ COVERAGE_MANIFEST=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.instrumented_files
+ export COVERAGE_DIR=bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test
+ COVERAGE_DIR=bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test
+ [[ bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test == /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__* ]]
+ COVERAGE_DIR=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test
+ mkdir -p /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test
+ COVERAGE_OUTPUT_FILE=bazel-out/darwin-fastbuild/testlogs/common_tools_test/coverage.dat
+ [[ bazel-out/darwin-fastbuild/testlogs/common_tools_test/coverage.dat == /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__* ]]
+ COVERAGE_OUTPUT_FILE=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/common_tools_test/coverage.dat
+ export JAVA_COVERAGE_FILE=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/jvcov.dat
+ JAVA_COVERAGE_FILE=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/jvcov.dat
+ export COVERAGE=1
+ COVERAGE=1
+ export BULK_COVERAGE_RUN=1
+ BULK_COVERAGE_RUN=1
+ [[ -z '' ]]
+ export GCOV_PREFIX_STRIP=3
+ GCOV_PREFIX_STRIP=3
+ export GCOV_PREFIX=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test
+ GCOV_PREFIX=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test
+ export LLVM_PROFILE_FILE=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/%h-%p-%m.profraw
+ LLVM_PROFILE_FILE=/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/%h-%p-%m.profraw
+ [[ -n '' ]]
+ [[ ! -z '' ]]
+ [[ 0 == \0 ]]
+ cd /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/__main__
+ [[ 0 == \0 ]]
+ touch /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/common_tools_test/coverage.dat
+ /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/__main__/common_tools_test '--junit-xml=$XML_OUTPUT_FILE' --ignore=external
Using toolchain coverage_tool 'python311_x86_64-apple-darwin_coverage/coverage/__main__.py'
Coverage entrypoint: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/__main__.py
============================= test session starts ==============================
platform darwin -- Python 3.11.1, pytest-7.3.1, pluggy-1.0.0
rootdir: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/__main__
collected 44 items

test/common_tools/test_cli.py ......                                     [ 13%]
test/common_tools/test_common.py ..                                      [ 18%]
test/common_tools/test_config.py ........................                [ 72%]
test/common_tools/test_ownership.py .......                              [ 88%]
test/common_tools/test_testing.py .....                                  [100%]

- generated xml file: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/common_tools_test/test.xml -
============================== 44 passed in 2.79s ==============================
Converting coveragepy database to lcov: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/19/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/pylcov.dat
No source for code: '/private/var/folders/6m/nl3wnqp96hz5b53qpx2y71f40000gp/T/pytest-of-nlou/pytest-313/test_load_config_from_fs0/dev/github.json'.   

<=============== created by `pytest tmpdir`
+ TEST_STATUS=1
+ [[ 1 -ne 0 ]]
+ echo --
--
+ echo Coverage runner: Not collecting coverage for failed test.
Coverage runner: Not collecting coverage for failed test.
+ echo The following commands failed with status 1
A clear and concise description of the problem...

🔬 Minimal Reproduction

🔥 Exception or Error





🌍 Your Environment

Operating System:

  
 darwin macos
  

Output of bazel version:

  
bazel 6.1.1
  

Rules_python version:

  
python_register_toolchains(
    name = "python311",
    python_version = "3.11",
    register_coverage_tool = True,
)
  

Anything else relevant?

@nlou9 nlou9 changed the title bazel coverage failed due to "no source file found" bazel coverage failed due to "No source for code" May 9, 2023
@aignas
Copy link
Collaborator

aignas commented May 12, 2023

Just an FYI, that there is a newer issue on the main bazel repo: bazelbuild/bazel#18362.

Copy link

github-actions bot commented Nov 8, 2023

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

@github-actions github-actions bot added the Can Close? Will close in 30 days if there is no new activity label Nov 8, 2023
Copy link

github-actions bot commented Dec 9, 2023

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

@github-actions github-actions bot closed this as completed Dec 9, 2023
@n3011
Copy link

n3011 commented Jan 5, 2024

Facing the same issue, any solutions?

@nlou9
Copy link
Author

nlou9 commented Apr 30, 2025

@n3011 this fix resolved our issue #2846

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Can Close? Will close in 30 days if there is no new activity
Projects
None yet
Development

No branches or pull requests

3 participants