pytest-dev / pytest-dev/pytest

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

Open
#13,964 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: warnings topic: collection type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the shown pyproject.toml setting and tests/test_foo.py example, running pytest --collectonly. Trace how strict mode handles pytest warnings and compare that with the documented warning configuration. Done means strict mode treats PytestCollectionWarning and other pytest warnings as errors by default, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.