Skip to content

Comments

Add strict_warnings mode for internal pytest warnings#14224

Open
coder-jatin-s wants to merge 3 commits intopytest-dev:mainfrom
coder-jatin-s:pytest
Open

Add strict_warnings mode for internal pytest warnings#14224
coder-jatin-s wants to merge 3 commits intopytest-dev:mainfrom
coder-jatin-s:pytest

Conversation

@coder-jatin-s
Copy link

Issue: #13964

This PR implements a strict warnings mode for internal pytest warnings.

Summary

  • Added a boolean ini option strict_warnings and a CLI flag --strict-warnings.
  • When strict warnings mode is enabled, all internal pytest warnings (pytest.PytestWarning and subclasses, including PytestCollectionWarning) are treated as errors.
  • Integrated the behavior into the existing warnings plugin so it works consistently during config, collection, and runtest phases.

Implementation details

  • In main.py:
    • Added an ini option:
      • strict_warnings = true|false
    • Added a CLI option:
      • --strict-warnings (in the pytest-warnings group), wired to config.option.strict_warnings.
  • In warnings.py:
    • Updated catch_warnings_for_item to compute:
      strict_warnings = bool(config.getini("strict_warnings")) or bool(
      getattr(config.option, "strict_warnings", False)
      )
      if strict_warnings:
      warnings.filterwarnings("error", category=pytest.PytestWarning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant