Make sure we can ignore internal pytest warnings using a warnings filter.
(
pytester: Pytester, ignore_pytest_warnings
)
| 342 | @pytest.mark.filterwarnings("default::pytest.PytestWarning") |
| 343 | @pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"]) |
| 344 | def test_hide_pytest_internal_warnings( |
| 345 | pytester: Pytester, ignore_pytest_warnings |
| 346 | ) -> None: |
| 347 | """Make sure we can ignore internal pytest warnings using a warnings filter.""" |
| 348 | pytester.makepyfile( |
| 349 | """ |
| 350 | import pytest |
| 351 | import warnings |
| 352 | |
| 353 | warnings.warn(pytest.PytestWarning("some internal warning")) |
| 354 | |
| 355 | def test_bar(): |
| 356 | pass |
| 357 | """ |
| 358 | ) |
| 359 | if ignore_pytest_warnings == "ini": |
| 360 | pytester.makeini( |
| 361 | """ |
| 362 | [pytest] |
| 363 | filterwarnings = ignore::pytest.PytestWarning |
| 364 | """ |
| 365 | ) |
| 366 | args = ( |
| 367 | ["-W", "ignore::pytest.PytestWarning"] |
| 368 | if ignore_pytest_warnings == "cmdline" |
| 369 | else [] |
| 370 | ) |
| 371 | result = pytester.runpytest(*args) |
| 372 | if ignore_pytest_warnings != "no": |
| 373 | assert WARNINGS_SUMMARY_HEADER not in result.stdout.str() |
| 374 | else: |
| 375 | result.stdout.fnmatch_lines( |
| 376 | [ |
| 377 | "*== %s ==*" % WARNINGS_SUMMARY_HEADER, |
| 378 | "*test_hide_pytest_internal_warnings.py:4: PytestWarning: some internal warning", |
| 379 | "* 1 passed, 1 warning *", |
| 380 | ] |
| 381 | ) |
| 382 | |
| 383 | |
| 384 | @pytest.mark.parametrize("ignore_on_cmdline", [True, False]) |
nothing calls this directly
no test coverage detected