Check that we collect files from __init__.py files when they patch the 'python_files' (#3773)
(pytester: Pytester)
| 1032 | |
| 1033 | |
| 1034 | def test_collect_init_tests(pytester: Pytester) -> None: |
| 1035 | """Check that we collect files from __init__.py files when they patch the 'python_files' (#3773)""" |
| 1036 | p = pytester.copy_example("collect/collect_init_tests") |
| 1037 | result = pytester.runpytest(p, "--collect-only") |
| 1038 | result.stdout.fnmatch_lines( |
| 1039 | [ |
| 1040 | "collected 2 items", |
| 1041 | "<Package tests>", |
| 1042 | " <Module __init__.py>", |
| 1043 | " <Function test_init>", |
| 1044 | " <Module test_foo.py>", |
| 1045 | " <Function test_foo>", |
| 1046 | ] |
| 1047 | ) |
| 1048 | result = pytester.runpytest("./tests", "--collect-only") |
| 1049 | result.stdout.fnmatch_lines( |
| 1050 | [ |
| 1051 | "collected 2 items", |
| 1052 | "<Package tests>", |
| 1053 | " <Module __init__.py>", |
| 1054 | " <Function test_init>", |
| 1055 | " <Module test_foo.py>", |
| 1056 | " <Function test_foo>", |
| 1057 | ] |
| 1058 | ) |
| 1059 | # Ignores duplicates with "." and pkginit (#4310). |
| 1060 | result = pytester.runpytest("./tests", ".", "--collect-only") |
| 1061 | result.stdout.fnmatch_lines( |
| 1062 | [ |
| 1063 | "collected 2 items", |
| 1064 | "<Package tests>", |
| 1065 | " <Module __init__.py>", |
| 1066 | " <Function test_init>", |
| 1067 | " <Module test_foo.py>", |
| 1068 | " <Function test_foo>", |
| 1069 | ] |
| 1070 | ) |
| 1071 | # Same as before, but different order. |
| 1072 | result = pytester.runpytest(".", "tests", "--collect-only") |
| 1073 | result.stdout.fnmatch_lines( |
| 1074 | [ |
| 1075 | "collected 2 items", |
| 1076 | "<Package tests>", |
| 1077 | " <Module __init__.py>", |
| 1078 | " <Function test_init>", |
| 1079 | " <Module test_foo.py>", |
| 1080 | " <Function test_foo>", |
| 1081 | ] |
| 1082 | ) |
| 1083 | result = pytester.runpytest("./tests/test_foo.py", "--collect-only") |
| 1084 | result.stdout.fnmatch_lines( |
| 1085 | ["<Package tests>", " <Module test_foo.py>", " <Function test_foo>"] |
| 1086 | ) |
| 1087 | result.stdout.no_fnmatch_line("*test_init*") |
| 1088 | result = pytester.runpytest("./tests/__init__.py", "--collect-only") |
| 1089 | result.stdout.fnmatch_lines( |
| 1090 | ["<Package tests>", " <Module __init__.py>", " <Function test_init>"] |
| 1091 | ) |
nothing calls this directly
no test coverage detected