Open matveypashkovskiy opened 3 years ago
I tried to replicate a similar situation and ran into a weird situation. If I have some similar code and run the coverage collection with pytest --cov=. --cov-context=test
and check how the coverage report looks, I get this:
So no test is recorded for the return key because there is no context for that line. But if change the source code like you did, the testname gets recorded:
I don't think I can come up with a fix for this with any pytest-cov flag. You can also check what kind of contexts your program has by setting
[html]
show_contexts = True
and checking the html report produced by coverage html
Update: for my example, this seems to be python version specific. The above situation is with 3.6.6
and with 3.8.5
the testname is recorded for the line in both cases. I had pytest-cov 2.11.1
and coverage 5.5
during both.
Here is an example from a project:
if the code is modified to:
no tests will be found for the change as DB contains no mapping info about
return (
line.Any ideas on how to fix it? Any magic pytest-cov flag maybe?