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

Possible missing warning filters in pytest_configure #10128

Open
akhilramkee opened this issue Jul 13, 2022 · 3 comments
Open

Possible missing warning filters in pytest_configure #10128

akhilramkee opened this issue Jul 13, 2022 · 3 comments
Labels
plugin: warnings related to the warnings builtin plugin topic: config related to config handling, argument parsing and config file type: question general question, might be closed after 2 weeks of inactivity

Comments

@akhilramkee
Copy link
Contributor

akhilramkee commented Jul 13, 2022

Is there a reason why we don't apply any other warning filters passed in pytest.ini. This seems like a possible bug,

warnings.simplefilter("default")

Output

user@system: ~/workspace/pytest-issue-reproducer/filter_config_warning$ pytest
/u/user/workspace/pytest-issue-reproducer/filter_config_warning/conftest.py:5: UserWarning: Some warning
  warnings.warn("Some warning", category=UserWarning)
================================================================================================================================== test session starts ===================================================================================================================================
platform linux -- Python 3.9.7, pytest-7.0.1, pluggy-1.0.0
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /u/user/workspace/pytest-issue-reproducer/filter_config_warning, configfile: pytest.ini
plugins: html-3.1.1, typeguard-2.12.1, json-report-1.4.1, tavern-1.20.0, flaky-3.7.0, allure-pytest-2.9.45, Faker-10.0.0, mock-3.6.1, cov-3.0.0, pyfakefs-4.5.3, xdist-2.5.0, json-0.4.0, benchmark-3.4.1, memray-1.2.0, anyio-3.4.0, subtests-0.8.0, nbval-0.9.6, hypothesis-6.32.1, forked-1.4.0, metadata-1.11.0
collected 1 item

tests/test_dummy.py .                                                                                                                                                                                                                                                              [100%]

=================================================================================================================================== 1 passed in 0.35s ====================================================================================================================================

Warning is thrown before test session starts

/u/user/workspace/pytest-issue-reproducer/filter_config_warning/conftest.py:5: UserWarning: Some warning
  warnings.warn("Some warning", category=UserWarning)

Reproducer

conftest.py

import pytest
import warnings

def pytest_configure(config: pytest.Config):
    warnings.warn("Some warning", category=UserWarning)

Content -> pytest.ini

[pytest]
filterwarnings =
        ignore::UserWarning

Warning gets filtered out in testcases as expected.

Possible fix:

  • Applying filters after warnings.simplefilter('default') using apply_warning_filters

def apply_warning_filters(

@Zac-HD Zac-HD added type: question general question, might be closed after 2 weeks of inactivity plugin: warnings related to the warnings builtin plugin topic: config related to config handling, argument parsing and config file labels Jul 13, 2022
@akhilramkee
Copy link
Contributor Author

@nicoddemus , any views on this ?

@nicoddemus
Copy link
Member

Hey @akhilramkee, sorry for not answering earlier.

I think this is mostly an oversight, can't think of a reason not to apply the filters at that stage.

@akhilramkee
Copy link
Contributor Author

akhilramkee commented Jul 18, 2022

Thanks for replying in short notice! Would it be fine if I send in a PR to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin topic: config related to config handling, argument parsing and config file type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants