def test_collection_warnings(pytester: Pytester) -> None:
    """Check that we also capture warnings issued during test collection (#3251)."""
    pytester.makepyfile(
        """
        import warnings

        warnings.warn(UserWarning("collection warning"))

        def test_foo():
            pass
    """
    )
    result = pytester.runpytest()
    result.stdout.fnmatch_lines(
        [
            f"*== {WARNINGS_SUMMARY_HEADER} ==*",
            "  *collection_warnings.py:3: UserWarning: collection warning",
            '    warnings.warn(UserWarning("collection warning"))',
            "* 1 passed, 1 warning*",
        ]
    )
Check that we also capture warnings issued during test collection (#3251).
testing/test_warnings.py