How to write plugin without lowering coverage reported by pytest-cov? #8468
Unanswered
andy-maier
asked this question in
Q&A
Replies: 1 comment 3 replies
-
(I'm short on time so I only read the issue in passing) When testing plugins, I avoid In those cases I run |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have written a pytest fixture that is parametrized with data from a config file. In a first attempt, I simply read the config file at the global module level where the fixture is defined, and used the result to parametrize the fixture. That all worked fine, but had the disadvantage that the config file is loaded at module import time, plus the control of which file was used and what was used from the file was via environment variables.
I then switched to writing a pytest plugin that implements the
pytest_generate_tests()
hook which loads the config file and parametrizes the fixture. That successfully deferred the loading of the config file until pytest runs. Also, the additional benefit of a plugin is that the control can now be done nicely via command line options.The plugin approach also works fine, but it caused the test coverage to drop dramatically. Here is the resulting dropped coverage:
The coverage of the same code, just without registering the plugin as an entry point, and without running the sample test function that uses the fixture, is:
Note that two less tests are run here, and the coverage is way up.
My suspicion is that the pytest-cov plugin that is used to measure/report the coverage is somehow impacted by my new plugin.
My implementation of the
pytest_generate_tests()
hook is here: https://github.com/andy-maier/client_end2end_tester/blob/master/client_end2end_tester/plugin.py#L72.My question is: What in my plugin causes the reported coverage to drop so dramatically, and how can I fix that.
One more tidbit: I tried to wrapper the
pytest_generate_tests()
hook with@pytest.hookimpl(hookwrapper=True)
but that resulted in:Pytest info:
Beta Was this translation helpful? Give feedback.
All reactions