Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module-level code imported from conftest files is reported as 'uncovered' #19

Closed
carljm opened this issue Oct 16, 2014 · 6 comments
Closed

Comments

@carljm
Copy link

carljm commented Oct 16, 2014

This is because pytest-cov doesn't actually start coverage measurement until pytest_sessionstart.

I think it could perhaps be fixed by starting coverage measurement instead in pytest_load_initial_conftests, but a few things about this make me nervous:

  1. If people are setting up their coverage options via some method other than command-line args (e.g. modifying the config in another hook or plugin) it would no longer take effect soon enough.

  2. I'm not familiar with the distributed-coverage aspect of pytest-cov and cov-core, so I'm not sure what implications there might be there.

@schlamar
Copy link
Contributor

Already implemented and released: #4

@schlamar
Copy link
Contributor

If you are already using using the new version, please give me more details, so we can work this out :) A failing test case would be the best.

@carljm
Copy link
Author

carljm commented Oct 17, 2014

Well, that's embarrassing. The new version does fix this. I didn't try upgrading because I looked at the latest code on GitHub, and although I saw the pytest_load_initial_conftests hook, it still looked to me like the actual start of coverage measurement didn't happen until the pytest_sessionstart hook in CovPlugin. But I guess pytest_sessionstart must fire earlier than I realized, at least in the non-distributed case?

In any case, thanks for having already fixed this, and sorry for the noise :-) Feel free to close.

@schlamar
Copy link
Contributor

Only slave coverage is started in pytest_sessionstart. Default coverage and coverage from the master in distributed case are actually started from pytest_load_initial_conftests in CovPlugin.__init__

@schlamar
Copy link
Contributor

BTW, I know the code is badly structured, that's for legacy reasons. I'm the maintainer for just a few months now. I'm planning a bigger rewrite but that's still in my head right now...

@carljm
Copy link
Author

carljm commented Oct 17, 2014

I see it now. Still don't know I missed the calls to start in CovPlugin.__init__.

Thanks for picking up maintenance of pytest-cov!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants