Check that we also capture warnings issued during test collection (#3251).
(pytester: Pytester)
| 301 | |
| 302 | @pytest.mark.filterwarnings("always::UserWarning") |
| 303 | def test_collection_warnings(pytester: Pytester) -> None: |
| 304 | """Check that we also capture warnings issued during test collection (#3251).""" |
| 305 | pytester.makepyfile( |
| 306 | """ |
| 307 | import warnings |
| 308 | |
| 309 | warnings.warn(UserWarning("collection warning")) |
| 310 | |
| 311 | def test_foo(): |
| 312 | pass |
| 313 | """ |
| 314 | ) |
| 315 | result = pytester.runpytest() |
| 316 | result.stdout.fnmatch_lines( |
| 317 | [ |
| 318 | "*== %s ==*" % WARNINGS_SUMMARY_HEADER, |
| 319 | " *collection_warnings.py:3: UserWarning: collection warning", |
| 320 | ' warnings.warn(UserWarning("collection warning"))', |
| 321 | "* 1 passed, 1 warning*", |
| 322 | ] |
| 323 | ) |
| 324 | |
| 325 | |
| 326 | @pytest.mark.filterwarnings("always::UserWarning") |
nothing calls this directly
no test coverage detected