Skip to content

Bazel coverage report file is empty when loading py_binary with Python version specified #1600

@tanan

Description

@tanan

🐞 bug report

Affected Rule

The issue is caused by the py_binary and py_test when running bazel coverage.

Is this a regression?

No.

Description

When I load py_binary and py_test with Python version specified like below and run bazel coverage command, a coverage report file is empty.

load("@python//3.10:defs.bzl", "py_binary", "py_test")

When I load these rules with the default Python version, the correct coverage report is created.

load("@rules_python//python:defs.bzl", "py_binary", "py_test")

🔬 Minimal Reproduction

Here is an example repository.
https://github.com/tanan/bazel-python-coverage/tree/python-coverage-empty

I run the command:

bazel coverage --combined_report=lcov //apps/demo/...

On the other hand, bazel coverage creates a correct file when I load the default version of py_binary and py_test. The sample repository is here:
https://github.com/tanan/bazel-python-coverage/tree/python-coverage-success

The difference between the two codes is the URL below.
tanan/bazel-python-coverage@python-coverage-success...python-coverage-empty

🔥 Exception or Error

coverage file is empty with the log WARNING: There was no coverage found.


$ bazel coverage --combined_report=lcov //apps/demo/...
Starting local Bazel server and connecting to it...
INFO: Using default value for --instrumentation_filter: "^//apps/demo[/:]".
INFO: Override the above default with --instrumentation_filter
INFO: Analyzed 3 targets (54 packages loaded, 3852 targets configured).
INFO: Found 2 targets and 1 test target...
INFO: LCOV coverage report is located at /home/foo/.cache/bazel/_bazel_foo/eb400fbb2bc2347b07965f1284d95f71/execroot/__main__/bazel-out/_coverage/_coverage_report.dat
 and execpath is bazel-out/_coverage/_coverage_report.dat
INFO: From Coverage report generation:
Dec 08, 2023 6:12:14 PM com.google.devtools.coverageoutputgenerator.Main getTracefiles
INFO: Found 1 tracefiles.
Dec 08, 2023 6:12:14 PM com.google.devtools.coverageoutputgenerator.Main parseFilesSequentially
INFO: Parsing file bazel-out/k8-fastbuild-ST-eff9b1c97e51/testlogs/apps/demo/lib_test/coverage.dat
Dec 08, 2023 6:12:14 PM com.google.devtools.coverageoutputgenerator.Main getGcovInfoFiles
INFO: No gcov info file found.
Dec 08, 2023 6:12:14 PM com.google.devtools.coverageoutputgenerator.Main getGcovJsonInfoFiles
INFO: No gcov json file found.
Dec 08, 2023 6:12:14 PM com.google.devtools.coverageoutputgenerator.Main getProfdataFileOrNull
INFO: No .profdata file found.
Dec 08, 2023 6:12:14 PM com.google.devtools.coverageoutputgenerator.Main runWithArgs
WARNING: There was no coverage found.
INFO: Elapsed time: 27.915s, Critical Path: 8.73s
INFO: 25 processes: 19 internal, 5 linux-sandbox, 1 worker.
INFO: Build completed successfully, 25 total actions
//apps/demo:lib_test                                                     PASSED in 7.1s

Executed 1 out of 1 test: 1 test passes.

🌍 Your Environment

Operating System:

  
Ubuntu 20.04.6 LTS
  

Output of bazel version:

  
Bazelisk version: v1.11.0
Build label: 6.3.2
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Aug 8 15:48:33 2023 (1691509713)
Build timestamp: 1691509713
Build timestamp as int: 1691509713
  

Rules_python version:

  
0.27.1
  

Anything else relevant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions