Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter warnings from AssertionRewritingHook when exec'ing module #12248

Closed
wants to merge 1 commit into from

Conversation

Redoubts
Copy link

This method raises warnings from packages very early in the pytest collection process, way before configured filterwarnings can be set up. It's not interesting to raise anything here IMO, so let's filter and ignore them.

This should also prevent spurious issue reports for you, like #11741 and #9884

This method raises warnings from packages very early in the pytest collection process, way before filterwarnings can be set up. It's not interesting to raise anything here, so lets catch and ignore them
@Redoubts
Copy link
Author

Basically this solves spam issues like:

% 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
...

It's not really impacting functionality, but it's annoying spam and sometimes the packages ultimately causing this have no fixes to pick up

Copy link
Member

@The-Compiler The-Compiler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, this causes any warnings at import time to be silenced completely?

If so, that definitely doesn't seem desirable to me. We should definitely improve our reporting to point out where they actually happen, maybe even make them filterable (say, maybe by catching and reraising them?), but silently suppressing them in a test runner of all places definitely isn't the thing to do.

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.

None yet

2 participants