def test_yield_disallowed_in_tests(pytester: Pytester):
    """Ensure generator test functions with 'yield' fail collection (#12960)."""
    pytester.makepyfile(
        """
        def test_with_yield():
            yield 1
        """
    )
    result = pytester.runpytest()
    assert result.ret == 2
    result.stdout.fnmatch_lines(
        ["*'yield' keyword is allowed in fixtures, but not in tests (test_with_yield)*"]
    )
    # Assert that no tests were collected
    result.stdout.fnmatch_lines(["*collected 0 items*"])
Ensure generator test functions with 'yield' fail collection (#12960).
testing/test_collection.py