pytest icon indicating copy to clipboard operation
pytest copied to clipboard

`PytestCollectionWarning` (and any other warnings) should be treated as an error in strict mode

Open DetachHead opened this issue 4 weeks ago • 2 comments

What's the problem this feature will solve?

when i enable the new strict mode in pytest settings, i expect any warnings to become errors. but there seems to still be some warnings where this isn't the case:

# pyproject.toml

[tool.pytest]
strict = true
# tests/test_foo.py

class TestFoo:
    def __new__(cls): ...
$ pytest --collectonly
===================================================================================== test session starts ======================================================================================
platform linux -- Python 3.14.0, pytest-8.4.2, pluggy-1.6.0
rootdir: /home/me/projects/test
configfile: pyproject.toml
collected 0 items                                                                                                                                                                              

======================================================================================= warnings summary =======================================================================================
tests/test_foo.py:3
  /home/me/projects/test/tests/test_foo.py:3: PytestCollectionWarning: cannot collect test class 'TestFoo' because it has a __new__ constructor (from: tests/test_foo.py)
    class TestFoo:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================= no tests collected in 0.01s ==================================================================================

Describe the solution you'd like

strict mode should make all pytest warnings an error by default

Alternative Solutions

configuring them as described here, but it would be much more convenient if i could enable all of pytest's strictness with a single setting.

DetachHead avatar Nov 14 '25 01:11 DetachHead