How to set up a different html output directory for coverage report using pytest?
Using coverage with pytests is a very useful tool.
Html reports allow good output, however through command line can't find option to change default output directory (htmlcov)
Command line example:
python -mpytest lib_being_tested \ tests --cov lib_being_tested.module --cov-report = html
source to share
This configuration parameter is not part of the pytest-cov
.
In the configuration file for the main tool coverage.py
, which is named by default .coveragerc
, you can add:
[html]
directory = differentname
See documentation for details: https://github.com/nedbat/coveragepy/blob/master/doc/config.rst
source to share
now (3 years later) you can change the default output directory directly on the command line:
python -m pytest --cov --cov-report=html:reports/html_dir --cov-report=xml:reports/coverage.xml lib_being_tested.module
Missing directories are created on the fly
Simeon's answer is still relevant for selecting this output directory via a coverage config file
source to share