I have a test suite that runs a bunch of system tests on an API. Some system tests interact with the API by using Flask's test_client, whereas a few specific tests interact with the API by making HTTP queries to a Gunicorn running the API.
When I use coverage, as soon as it hits those special tests that use Gunicorn, a warning is shown:
CoverageWarning: No data was collected. (no-data-collected)
The warning makes perfect sense—coverage cannot track the actual coverage in tests when the tested API runs through Gunicorn, instead of being called directly. However, it's annoying to see this warning at every test run.
How do I hide it for those specific tests, while ensuring it will be shown if the coverage for other tests starts misbehaving?
A few additional details:
All tests (both the ones that rely on Flask's test_client and the ones that do HTTP queries to Gunicorn) are run in one go with the command:
coverage run --rcfile=coverage-options -m unittest discover tests/ --failfast
The contents of the aforementioned coverage-options file are:
[run]
branch = True
concurrency = multiprocessing
omit =
/usr/*/dist-packages/*
*/.local/lib/*/site-packages/*
tests/*
The tests/ directory contains several sub-directories:
tests/api/: about one hundred and thirty tests that rely ontest_client.tests/system/: four tests that perform HTTP queries to Gunicorn.tests/unit/: seven very basic tests.
The output is:
(.venv) ~/src/example$ coverage run --rcfile=coverage-options -m unittest discover tests/ --failfast
...................................................................................................................................../home/u/src/example/.venv/lib/python3.13/site-packages/coverage/control.py:915: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected")
.../home/u/src/example/.venv/lib/python3.13/site-packages/coverage/control.py:915: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected")
.......
----------------------------------------------------------------------
Ran 143 tests in 45.853s
OK
As tests are ran in alphabetical order, the first one hundred and thirty something dots match the tests in tests/api/. The last seven correspond to the unit tests. The warnings are shown once the very first test from tests/system/ gets executed, and then once again when all four are executed.
By comparison, if I remove tests/system/ directory, this is what I get:
(.venv) ~/src/example$ coverage run --rcfile=coverage-options -m unittest discover tests/ --failfast
...........................................................................................................................................
----------------------------------------------------------------------
Ran 139 tests in 38.022s
OK
coverage run --rcfile=coverage-options -m unittest discover tests --failfast, and mycoverage-optionsfile containsbranch = True,concurrency = multiprocessing, and a bunch of directories to exclude from coverage.multiprocessing.Processexits (which was happening in two of the tests). Now, why does it do that, and what is the cleanest way to deal with it, is another subject.