question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some internal warnings from pytest cannot be filtered with settings in pytest.ini

See original GitHub issue

I 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:

  1. pytest.ini file as shown above
  2. empty directory .pytest_cache with 444 permissions
  3. 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:closed
  • Created 4 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
sanyasshcommented, Feb 17, 2020

@blueyed there are at least two cases:

  1. I run pytest inside docker container and if I don’t specify a writable bind for .pytest_cache directory, I get PytestCacheWarning because pytest is not able to write a cache.
  2. I import conftest_additional.py inside main conftest.py and thus get PytestAssertRewriteWarning: 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)

1reaction
pllimcommented, Aug 3, 2020

I started seeing this too with pytest 6.0.0 that also cannot be ignored with filterwarnings:

    self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))
.../python3.7/site-packages/_pytest/config/__init__.py:1148
  .../python3.7/site-packages/_pytest/config/__init__.py:1148: PytestConfigWarning: Unknown config ini key: qt_no_exception_capture

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found