-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Incorrect coverage report #277
Comments
@drasmuss could you try this with the master of pytest-cov? |
(in case using master does not fix it) |
Unfortunately master looks like it has the same behaviour. You can see an example of the missing lines here https://codecov.io/gh/nengo/nengo/src/template-ci/nengo/base.py (that file has 100% coverage when not running through Is there anything we can do to avoid that? I tried setting the |
To clarify what's going on there ... xdist is being used. Actual command is So this test suite only runs on travis? It looks like you pushed a commit just to try the master of pytest-cov. |
I'm testing it with and without xdist. You can see without xdist here: and without xdist, without pytest-cov here: We do eventually want to run with xdist (that's why we're interested in pytest-cov), but I took xdist out of the equation for now to simplify the debugging. And yes, this issue seems to be environment specific, when I run it on my local machine I don't see the issue. So I have to do everything through travis for now. |
Well something really funny is going on there. Does the problem go away if you remove the |
No change after removing the entrypoint, unfortunately. |
Well one way to really nail this down is to have an early failure in |
That helped me track the issue down to this line https://github.com/nengo/nengo/blob/master/setup.cfg#L41, which I had forgotten we were setting. So that definitely makes sense that early-loading that file would mess up the import order. Do you know if there is a simple way to make |
https://pytest-cov.readthedocs.io/en/latest/plugins.html should solve it. If it doesn't show a failing build with the applied configuration. |
Using |
Interesting, is this implemented in master already @nicoddemus ? |
No, only in
I think we will release 4.4 this week or the next, I believe. 👍 |
Manually starting the pytest-cov engine as in https://pytest-cov.readthedocs.io/en/latest/plugins.html solved the problem for me, thanks! I swear I tried that before, but I must have had some other changes happening at the same time that prevented it from working 🤷♂️ . And if I understand things correctly, after pytest 4.4 we could accomplish a similar thing, early starting the pytest-cov engine, via
? |
Yes, and you probably won't need |
Minor update: I found that manually starting the pytest-cov engine works, unless we use one of the options defined in the plugin that we're trying to get pytest-cov to load before. E.g.,
works, but
results in the same incorrect coverage report as before. My guess would be that when pytest has to execute the custom plugin code to evaluate that argument, that preempts what we're trying to do with the manual pytest-cov start. In any case, it seems like this is something that isn't really in |
Arguments (and the plugin) are loaded regardless of options are used. But likely the plugin itself then imported things already?! |
Same problem here. I have tried |
@lephuongbg do you have an example project that reproduces the problem? |
@ionelmc I can't guarantee to have time to make an example project from our large code base but I have found the way to circumvent the problem: OUR SOLUTION: At the top of our The thing is, we didn't have to do that until now. Our code has changed but the |
I had a similar issue. What I found is that tox installs the package being tested into its virtualenv. However, coverage looks for the package in the working directory. Thus, it looks as though the files have 0% coverage -- and they do, because the coverage info has been recorded against the copy installed in the tox directory. What I don't understand is if you pass In any case, I was able to fix this by adding the |
I have the same issue |
Thank you for this thread! I was running into the same problem. In my case I was able to get it working using [tool.hatch.envs.test.scripts]
pytest = "coverage run -m pytest {args}"
...
[tool.pytest.ini_options]
addopts = "-p pytest_cov --cov=src --cov-append" It was important that I include the both the |
I found some success in using |
This issue can be observed in this log https://travis-ci.org/nengo/nengo/jobs/510052898#L894. Sorry I couldn't come up with a smaller test case, but it seems to be a specific interaction with this repo somehow.
Specifically, running tests with
reports 69% test coverage, while
reports 82% coverage (scroll farther down in the log to see this). My understanding is that those two should be equivalent.
This was previously reported in #117, but the fixes there didn't solve the problem (I figured since that one had been closed for two years it was better to open a new issue).
The text was updated successfully, but these errors were encountered: