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

Bug: filterwarnings doesn't work for pytest plugins #12756

Closed
jamesbraza opened this issue Aug 30, 2024 · 2 comments
Closed

Bug: filterwarnings doesn't work for pytest plugins #12756

jamesbraza opened this issue Aug 30, 2024 · 2 comments

Comments

@jamesbraza
Copy link

In pytest-dev/pytest-asyncio@c74d1c3, pytest-asyncio==0.24.0 (which is a pytest plugin) added a PytestDeprecationWarning that I am now trying to silence.

I have noticed this PytestDeprecationWarning is different from normal dependencies' DeprecationWarning because it's emitted before pytest loads, instead of at test time.

I have configured filterwarnings for many normal packages, but I can't get it to work for this "pre-pytest loaded" PytestDeprecationWarning:

[tool.pytest.ini_options]
filterwarnings = [
    'ignore:configuration option "asyncio_default_fixture_loop_scope" is unset',
]

I have concluded that filterwarnings doesn't seem to work on pytest plugins.

Thus, I think this is a sort of bug, so I am requesting to apply filterwarnings also to pytest plugins, not just normal test time dependencies.

@jamesbraza jamesbraza changed the title filterwarnings doesn't work for pytest plugins Bug: filterwarnings doesn't work for pytest plugins Aug 30, 2024
@dongfangtianyu
Copy link
Contributor

dongfangtianyu commented Sep 4, 2024

Looks the same as #12697 .

Pytest will intercept and capture warnings in the collection of use cases.
Prior to this, if wanted to filter specified warnings, couldn't rely on pytest but on python.

for example

python -W ignore::DeprecationWarning    -m pytest

However, due to this line of code, doing so is actually ineffective:
https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/__init__.py#L1116


It may be necessary a new feature :capture warnings when the plugin is loading.

@bluetech
Copy link
Member

bluetech commented Sep 4, 2024

Thanks @dongfangtianyu for the reference, closing as a duplicate of #12697.

@bluetech bluetech closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
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

No branches or pull requests

3 participants