Skip to content

bazel coverage is not showing the number of functions hit/coverageΒ #2706

@wsoesanto-arbo

Description

@wsoesanto-arbo

🐞 bug report

Affected Rule

The issue is caused by the rule: py_test.

Is this a regression?

Not sure.

Description

I have the following python library file.

def sum(a: int, b: int) -> int:
    if a == 0:
        return b
    return a + b


def uncalled_function():
    pass

The test file is the following:

import unittest
from pytestcoverage.example import sum


class ExampleTest(unittest.TestCase):

    def test_example(self):
        self.assertEqual(sum(1, 2), 3)

    def test_example2(self):
        self.assertEqual(sum(0, 2), 2)


if __name__ == "__main__":
    unittest.main()

I ran bazel coverage //pytestcoverage:example_test and it produces the following .dat file.

SF:pytestcoverage/example.py
FNF:0
FNH:0
BRDA:3,0,0,1
BRDA:4,0,1,1
BRF:2
BRH:2
DA:1,1,TEm0m03zdmZoLvEEYvcd3g
DA:2,1,qz5GR5TDab0xK5yEyEXvVA
DA:3,1,iX7Q3CYbMsKz6tK3+NbOAQ
DA:4,1,Ro176RhJvDYGuBP1DF9bzA
DA:7,1,QO5oDInC/FETpNCZmYWtnA
DA:8,0,PdeqDqr4bOft68ON3+/7kg
LH:5
LF:6
end_of_record

It seems it's able to know which line is covered. Unfortunately it couldn't tell the number of functions that are covered. Hence 0 value on FNF and FNH. This can also be seen from genhtml lcov program.

πŸ”¬ Minimal Reproduction

https://github.com/wsoesanto-arbo/pytestcoverage

πŸ”₯ Exception or Error

No error

🌍 Your Environment

Operating System:

  
Linux sg-dev-willy 6.8.0-52-generic #53~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 15 19:18:46 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
  

Output of bazel version:

  
7.5.0
  

Rules_python version:

  
http_archive(
    name = "rules_python",
    sha256 = "2ef40fdcd797e07f0b6abda446d1d84e2d9570d234fddf8fcd2aa262da852d1c",
    strip_prefix = "rules_python-1.2.0",
    url = "https://github.com/bazelbuild/rules_python/releases/download/1.2.0/rules_python-1.2.0.tar.gz",
)
  

Anything else relevant?

I think I have provided the most basic information on the setup. Let me know if you need more information on it. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions