rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

bazel coverage produces empty coverage analysis reports and a message about missing GCov when running against a py_test target

Open TeodorMalbasic opened this issue 2 months ago β€’ 10 comments

🐞 bug report

Affected Rule

The issue is caused by the rule: py_test()

Is this a regression?

No

Description

After the successful execution of the bazel test command I attempted to add the coverage tool too.

Unfortunately, I get output:

GCov does not exist at the given path: '' Oct 13, 2025 12:50:34 PM com.google.devtools.coverageoutputgenerator.Main runWithArgs WARNING: There was no coverage found.

I want to use the coverage (opensource) pip package for gathering coverage data of Python tests. I have no clue why running bazelisk coverage --combined_report=lcov //... --test_output=all returns that GCov does not exist.

My test scripts are written with unittest framework, and they successfully run with bazelisk test :all --test_output=all

πŸ”¬ Minimal Reproduction

https://github.com/TeodorMalbasic/bazel_coverage_target_issue.git

πŸ”₯ Exception or Error



 
GCov does not exist at the given path: ''
Oct 13, 2025 12:50:34 PM com.google.devtools.coverageoutputgenerator.Main runWithArgs
WARNING: There was no coverage found.

🌍 Your Environment

Operating System:

  
Ubuntu 24.04
  

Output of bazel version:

  
bazel 8.4.2
  

Rules_python version:

  
Python 3.12.3 on machine, Python 3.12.11 in MODULE.bazel
  

Anything else relevant?

TeodorMalbasic avatar Oct 13 '25 14:10 TeodorMalbasic

Could you please share your repo so that I can look at the repro please?

aignas avatar Oct 14 '25 01:10 aignas

@aignas shared

TeodorMalbasic avatar Oct 14 '25 07:10 TeodorMalbasic

I am not sure if you should include the coverage dependency in the test - the toolchain will include it automatically if you specify the extra flag when configuring it in your MODULE.bazel file. Maybe this is related to that. As it is the repro does not have any python files, so I cannot verify if this is correct.

aignas avatar Oct 14 '25 08:10 aignas

It should be OK to include coverage in deps manually. All the bootstrap does is import coverage so it shouldn't be particular about where it comes from.

That said, don't we apply some patches to the coverage bundled with the toolchain? It could be the user space coverage is being used, but without that patches, something goes awry.

rickeylev avatar Oct 14 '25 09:10 rickeylev

@aignas originally, the solution was without coverage as dependency. I had the same output of GCov not existing.

TeodorMalbasic avatar Oct 14 '25 12:10 TeodorMalbasic

Ah, is it not the case that you need to install gcov on your host to be able to run the bazel coverage command? rules_python is not doing anything here and searching the code of bazel itself seems to suggest that this may be the case: https://github.com/search?q=repo%3Abazelbuild%2Fbazel+GCov&type=code&p=1

I am inclined to close this as won't do because it is out of scope for rules_python.

aignas avatar Oct 15 '25 02:10 aignas

@aignas If I understood correctly, action from my side would be to install gcov on my host machine? If so, is there any specific version (or range of versions) of gcov that I need to install?

TeodorMalbasic avatar Oct 15 '25 10:10 TeodorMalbasic

I'm having the same issue for Python coverage, but C++ coverage works fine.

lalten avatar Oct 15 '25 10:10 lalten

@aignas I checked if I have gcov installed, and I do. After running gcov --version, output is: gcov (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Anyway, If I need to open a new ticket somewhere else, please point me to the right direction, since I'm just starting with using Bazel, I don't yet know my way around. Thank you in advance!

TeodorMalbasic avatar Oct 16 '25 08:10 TeodorMalbasic

Hello @aignas, Is it possible to transfer the ticket if it is out of scope for this repository?

TeodorMalbasic avatar Oct 20 '25 08:10 TeodorMalbasic