Closed Spectre5 closed 1 month ago
Python has changed between versions about how it reports lines being executed. I suspect this is the reason for the def
line appearing and disappearing. If you have flexibility about what version of Python to use, use the one that gives you the results you like.
Sorry if I've missed something here.
You probably haven't missed anything and something along these lines is what I was expected. I was hoping there might be some work around to it that you were aware of. I didn't include it in this MWE, but in my actual code I also run coverage on some Python 3 code, so I was hoping to use Python 3 for the coverage session where I'd also combine the coverage before reporting it.
Have you tried combining the two runs together and then reporting on the combined data?
If I test the same code in Python 2 and 3 and then combine it, then I get 100% coverage, as expected. However, in my larger application, some of the code is only run on Python 2.7, so when I combine and report with that I get those missing lines as indicated above.
However, it does seem to work if I just use Python 2.7 for the coverage step (to combine and report). So I'll just do that, though in this project there is very little Python 3 code so perhaps this solution would also have issues with some aspects of Python 3. But at least it works for me at the moment.
Have you asked elsewhere?
No.
Describe your situation
I have a situation where I need to run coverage on some older Python 2.7 code (it runs on a legacy closed system and I sadly cannot upgrade it to Python 3 at this time) as well as some Python 3 code. Thus I'd like to run
coverage combine
andcoverage report
from a Python 3 environment. For the most part, this seems to work. However, I've found that thedef
line from Python 2.7 code that is decorated with@property
gets reported as not being covered.I suppose this may be due to some difference in the SQL file produced by 2.7 and then read in 3.x. Perhaps I'm foolish for expecting that this may work with the changes between 2.7 and 3.x. Would you expect this to work? I've boiled it down to a minimal working example provided below and verified the behavior on both Windows and Linux.
The directory layout is:
where
nox
has been used to simplify the multiple environments. The contents of each file is:dummy.py
:test_dummy.py
.coveragerc
noxfile.py
Run this from the top level using the follow (
rm
used to clean the directory on each run):The result coverage reported from this is the following, where line 6 is
def prop_x(self):
However, if I instead use
python='2.7'
for the coverage session in nox, then the coverage is correctly reported as 100%: