I am trying to get coverage on a Python process spawned by pytest. Here are the steps I took:
- Create a sitecustomize.py module in my local site packages directory
#/home/Olumide/.local/lib/python3.10/site-packages/sitecustomize.py
import coverage
coverage.process_startup()
- Set the
COVERAGE_PROCESS_STARTenvironment variable as followsexport COVERAGE_PROCESS_START=True - Run the test
coverage run --rcfile=.coveragerc -m pytest tests/gui/test_screenshots.pywhere the current directory contains the the .coveragerc file
[run]
source = src/
parallel = True
relative_files = True
omit =
**/tests/*
Note that the script tests/gui/test_screenshots.py launches an external python application that I want coverage on.
Unfortunately I'm still getting the warning:
/home/Olumide/repos/app/3.10_env/lib/python3.10/site-packages/coverage/control.py:887: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected")
Update
Found a 53248 byte .coverage file (called .coverage.Ubuntu-22.5371.XcjyqXNx) in the directory from which I ran the test. I can generate an HTML report from this file via the command:
coverage html --data-file=.coverage.Ubuntu-22.5371.XcjyqXNx.
So it looks like I've got coverage! Oddly though, only the __init__.py files have coverage stats (100%). I wonder whether this is what the warning message meant.
The docs say,
You need to use the path to your config file as the value of the environment variable.