How to get coverage reporting when testing a pytest plugin?
Instead of using the pytest-cov plugin, use coverage to run pytest: coverage run -m pytest …. That way, coverage will be started before pytest.
Instead of using the pytest-cov plugin, use coverage to run pytest: coverage run -m pytest …. That way, coverage will be started before pytest.
@hynekcer gave me the right idea. But basically the easiest solution lies somewhere else: Get rid of pytest-cov! Use coverage run –source jedi -m py.test coverage report instead!!! This way you’re just running a coverage on your current py.test configuration, which works perfectly fine! It’s also philosophically the right way to go: Make each program … Read more
For me the best solution was what @Wesley mentioned in his comment to the accepted answer, specifically replacing ‘pass’ with a docstring for the abstract property, e.g.: class MyAbstractClass(object): __metaclass__ = ABCMeta @abstractproperty def myproperty(self): “”” this property is too abstract to understand. “””
coverage (used by pytest-cov) needs the tests folder to contain an __init__.py before it will collect any data. I added __init__.py to the tests folder and then coverage collected the data as expected. Refer to http://thomas-cokelaer.info/blog/2017/01/pytest-cov-collects-no-data-on-travis/
Add –source=. to the coverage run line. It will both limit the focus to the current directory, and will search for .py files that weren’t run at all.
You can omit modules with the –omit flag. It takes a comma-separated list of path prefixes. So for example: coverage run my_program.py coverage report –omit=path/to/3rdparty
Have you tried pip install coverage? The coverage plugin depends on separate coverage module, which is not a nose’s dependency, so needs to be installed manually.
Coverage looks for a .coverage file to read and generate that report for you. Py.test on its own does not create one. You need py.test plugin for coverage: pip install pytest-cov If you already have it, then you can run both at once like this: py.test test.py –cov=sample.py Which means run test module test.py and … Read more
coverage html –omit=”*/test*” -d tests/coverage