WithSecureOpenSource / pytest-rts

Coverage-based regression test selection (RTS) plugin for pytest
Apache License 2.0
7 stars 3 forks source link

Statements "return (" have no coverage data #101

Open matveypashkovskiy opened 3 years ago

matveypashkovskiy commented 3 years ago

Here is an example from a project:

return (
  df
  .withColumnRenamed("a", "b")
)

if the code is modified to:

return self.reset(
  df
  .withColumnRenamed("a", "b")
)

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?

guotin commented 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:

cov_problem

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:

cov_problem2

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

guotin commented 3 years ago

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.