pytest-dev / pytest-dev/pytest

Handle warnings raised at import time early in pytest process

Open
#12,249 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

As noted in https://github.com/pytest-dev/pytest/pull/12248, some modules can raise warnings at import time. If this happens during AssertionRewritingHook's actions, then they get raised early and cannot be controlled by the pytest filterwarnings config, which is unfortunate. There should be a good way to suppress these with normal pytest config options.

Currently witnessing this on platform linux -- Python 3.11.9, pytest-8.1.1, pluggy-1.4.0

Example issue:

% pytest some_test.py

<venv>/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:178: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  exec(co, module.__dict__)
<venv>/lib/python3.11/site-packages/pkg_resources/__init__.py:2832: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('sphinxcontrib')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
============================================= test session starts =============================================
platform linux -- Python 3.11.9, pytest-8.1.1, pluggy-1.4.0
...

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

Start by reproducing the warning with pytest some_test.py on the stated Python and pytest versions, then inspect _pytest/assertion/rewrite.py, especially AssertionRewritingHook. Trace how import-time warnings are raised before pytest configuration is applied. Done means warnings from this phase can be controlled through normal pytest filterwarnings configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
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.