Skip to content

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

@DetachHead

Description

@DetachHead

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: warningsrelated to the warnings builtin plugintopic: collectionrelated to the collection phasetype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions