-
-
Notifications
You must be signed in to change notification settings - Fork 456
Description
Describe the bug
I want to use [run]patch = subprocess
together with --branch
but I'm getting unexpected results.
To Reproduce
- Python 3.13 on Debian Trixie x86_64
- Coverage.py, version 7.10.2 with C extension
- No other non-standard packages required
- Script content (subfunctions.py):
import subprocess
import argparse
def f1():
print("function 1")
def f2():
print("function 2")
def f3():
print("function 3")
functions = [f1, f2, f3]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("cases", nargs='+', type=int)
args = parser.parse_args()
if len(args.cases) > 1:
for c in args.cases:
subprocess.call(["python", __file__, f"{c}"])
else:
case = args.cases[0]
functions[case]()
if __name__ == '__main__':
main()
.coveragerc
content:
[run]
patch = subprocess
coverage run --branch subfunctions.py 0 1 2 && coverage combine && coverage report
Expected behavior
The coverage combine
step finishes and coverage report
probably shows 100% coverage including branch coverage.
Instead, the step of coverage combine
errors with a message similar to:
Combined data file .coverage.localhost.233908.XKcIJtPx
Can't combine statement coverage data with branch data
Additional context
This is a minimized reproducer. I ran into a problem in the context of an existing project when I tried to adapt it to use patch=subprocess
.
My guess is that the --branch
flag is not being propagated to the subprocesses. When the --branch
flag is not specified, things seem to work properly.
My reproducer does appear to work properly if [run] branch=true
is added to the applicable coveragerc instead of being specified on the commandline.