Some internal warnings from pytest cannot be filtered with settings in pytest.ini
See original GitHub issueI want to disable PytestCacheWarning
with the following pytest.ini
file:
[pytest]
filterwarnings =
ignore::pytest.PytestCacheWarning
But the warnings are still shown in report summary. Minimal reproducible example:
pytest.ini
file as shown above- empty directory
.pytest_cache
with 444 permissions - running pytest gives the following:
~/repos/reproduce_pytest_bug$ pytest
============= test session starts =================
platform linux -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /home/sanyash/repos/reproduce_pytest_bug, inifile: pytest.ini
plugins: celery-4.4.0, aiohttp-0.3.0
collected 0 items
============= warnings summary ================
/home/sanyash/.local/lib/python3.7/site-packages/_pytest/cacheprovider.py:137
/home/sanyash/.local/lib/python3.7/site-packages/_pytest/cacheprovider.py:137: PytestCacheWarning: could not create cache path /home/sanyash/repos/reproduce_pytest_bug/.pytest_cache/v/cache/stepwise
self.warn("could not create cache path {path}", path=path)
/home/sanyash/.local/lib/python3.7/site-packages/_pytest/cacheprovider.py:137
/home/sanyash/.local/lib/python3.7/site-packages/_pytest/cacheprovider.py:137: PytestCacheWarning: could not create cache path /home/sanyash/repos/reproduce_pytest_bug/.pytest_cache/v/cache/nodeids
self.warn("could not create cache path {path}", path=path)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
============= 2 warnings in 0.00s =============
versions:
- Ubuntu 18.04
- Python 3.7.6
- pytest 5.3.5
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
How to capture warnings — pytest documentation
These warnings might be filtered using the same builtin mechanisms used to filter other types of warnings.
Read more >How to suppress py.test internal deprecation warnings
It seems that pytest completely removes filters, because it shows all those DeprecationWarning when running, and Python's documentation ...
Read more >pytest Documentation - Read the Docs
pytest -h | --help # show help on command line and config file options ... filterwarnings - filter certain warnings of a test...
Read more >1417920 - Silence pytest warnings about build system classes ...
Bug 1417920 - [python-test] Use a global pytest.ini configuration file, ... 0:02.68 cannot collect test class 'TestManifestBackend' because it has a ...
Read more >pytest Changelog - pyup.io
This solves some issues with tests that involve pytest environment variables. ... Collector` so it can be filtered using :ref:`standard warning filters ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@blueyed there are at least two cases:
PytestCacheWarning
because pytest is not able to write a cache.conftest_additional.py
inside mainconftest.py
and thus getPytestAssertRewriteWarning: Module already imported so cannot be rewritten: conftest_additional
. I dont know yet how to work around it.I believe that every such case can be handled in proper way, but the simplest is just disabling all internal warnings because I dont care much about them (I can be wrong here and maybe I should care, but they really don’t seem critical)
I started seeing this too with
pytest
6.0.0 that also cannot be ignored withfilterwarnings
:The config is added just in case someone has
pytest-qt
installed but it is not installed in any circumstances in the project itself. So we know it is not used and we just want to silence the warning. Thanks.