def test_collect_init_tests(pytester: Pytester) -> None:
    """Check that we collect files from __init__.py files when they patch the 'python_files' (#3773)"""
    p = pytester.copy_example("collect/collect_init_tests")
    result = pytester.runpytest(p, "--collect-only")
    result.stdout.fnmatch_lines(
        [
            "collected 2 items",
            "<Dir *>",
            "  <Package tests>",
            "    <Module __init__.py>",
            "      <Function test_init>",
            "    <Module test_foo.py>",
            "      <Function test_foo>",
        ]
    )
    result = pytester.runpytest("./tests", "--collect-only")
    result.stdout.fnmatch_lines(
        [
            "collected 2 items",
            "<Dir *>",
            "  <Package tests>",
            "    <Module __init__.py>",
            "      <Function test_init>",
            "    <Module test_foo.py>",
            "      <Function test_foo>",
        ]
    )
    # Ignores duplicates with "." and pkginit (#4310).
    result = pytester.runpytest("./tests", ".", "--collect-only")
    result.stdout.fnmatch_lines(
        [
            "collected 2 items",
            "<Dir *>",
            "  <Package tests>",
            "    <Module __init__.py>",
            "      <Function test_init>",
            "    <Module test_foo.py>",
            "      <Function test_foo>",
        ]
    )
    # Same as before, but different order.
    result = pytester.runpytest(".", "tests", "--collect-only")
    result.stdout.fnmatch_lines(
        [
            "collected 2 items",
            "<Dir *>",
            "  <Package tests>",
            "    <Module __init__.py>",
            "      <Function test_init>",
            "    <Module test_foo.py>",
            "      <Function test_foo>",
        ]
    )
    result = pytester.runpytest("./tests/test_foo.py", "--collect-only")
    result.stdout.fnmatch_lines(
        [
            "<Dir *>",
            "  <Package tests>",
            "    <Module test_foo.py>",
            "      <Function test_foo>",
        ]
    )
    result.stdout.no_fnmatch_line("*test_init*")
    result = pytester.runpytest("./tests/__init__.py", "--collect-only")
    result.stdout.fnmatch_lines(
        [
            "<Dir *>",
            "  <Package tests>",
            "    <Module __init__.py>",
            "      <Function test_init>",
        ]
    )
    result.stdout.no_fnmatch_line("*test_foo*")
Check that we collect files from __init__.py files when they patch the 'python_files' (#3773)
testing/test_collection.py