File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,46 @@ def test_foo():
349
349
)
350
350
351
351
352
+ @pytest .mark .filterwarnings ("default" )
353
+ @pytest .mark .parametrize ("ignore_pytest_warnings" , ["no" , "ini" , "cmdline" ])
354
+ def test_hide_pytest_internal_warnings (testdir , ignore_pytest_warnings ):
355
+ """Make sure we can ignore internal pytest warnings using a warnings filter."""
356
+ testdir .makepyfile (
357
+ """
358
+ import pytest
359
+ import warnings
360
+
361
+ warnings.warn(pytest.PytestWarning("some internal warning"))
362
+
363
+ def test_bar():
364
+ pass
365
+ """
366
+ )
367
+ if ignore_pytest_warnings == "ini" :
368
+ testdir .makeini (
369
+ """
370
+ [pytest]
371
+ filterwarnings = ignore::pytest.PytestWarning
372
+ """
373
+ )
374
+ args = (
375
+ ["-W" , "ignore::pytest.PytestWarning" ]
376
+ if ignore_pytest_warnings == "cmdline"
377
+ else []
378
+ )
379
+ result = testdir .runpytest (* args )
380
+ if ignore_pytest_warnings != "no" :
381
+ assert WARNINGS_SUMMARY_HEADER not in result .stdout .str ()
382
+ else :
383
+ result .stdout .fnmatch_lines (
384
+ [
385
+ "*== %s ==*" % WARNINGS_SUMMARY_HEADER ,
386
+ "*test_hide_pytest_internal_warnings.py:4: PytestWarning: some internal warning" ,
387
+ "* 1 passed, 1 warnings *" ,
388
+ ]
389
+ )
390
+
391
+
352
392
class TestDeprecationWarningsByDefault :
353
393
"""
354
394
Note: all pytest runs are executed in a subprocess so we don't inherit warning filters
You can’t perform that action at this time.
0 commit comments