pytest-dev / pytest-dev/pytest
Handle warnings raised at import time early in pytest process
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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