(self, pytester: Pytester)
| 1140 | |
| 1141 | class TestNewFirst: |
| 1142 | def test_newfirst_usecase(self, pytester: Pytester) -> None: |
| 1143 | pytester.makepyfile( |
| 1144 | **{ |
| 1145 | "test_1/test_1.py": """ |
| 1146 | def test_1(): assert 1 |
| 1147 | """, |
| 1148 | "test_2/test_2.py": """ |
| 1149 | def test_1(): assert 1 |
| 1150 | """, |
| 1151 | } |
| 1152 | ) |
| 1153 | |
| 1154 | p1 = pytester.path.joinpath("test_1/test_1.py") |
| 1155 | os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9))) |
| 1156 | |
| 1157 | result = pytester.runpytest("-v") |
| 1158 | result.stdout.fnmatch_lines( |
| 1159 | ["*test_1/test_1.py::test_1 PASSED*", "*test_2/test_2.py::test_1 PASSED*"] |
| 1160 | ) |
| 1161 | |
| 1162 | result = pytester.runpytest("-v", "--nf") |
| 1163 | result.stdout.fnmatch_lines( |
| 1164 | ["*test_2/test_2.py::test_1 PASSED*", "*test_1/test_1.py::test_1 PASSED*"] |
| 1165 | ) |
| 1166 | |
| 1167 | p1.write_text( |
| 1168 | "def test_1(): assert 1\ndef test_2(): assert 1\n", encoding="utf-8" |
| 1169 | ) |
| 1170 | os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9))) |
| 1171 | |
| 1172 | result = pytester.runpytest("--nf", "--collect-only", "-q") |
| 1173 | result.stdout.fnmatch_lines( |
| 1174 | [ |
| 1175 | "test_1/test_1.py::test_2", |
| 1176 | "test_2/test_2.py::test_1", |
| 1177 | "test_1/test_1.py::test_1", |
| 1178 | ] |
| 1179 | ) |
| 1180 | |
| 1181 | # Newest first with (plugin) pytest_collection_modifyitems hook. |
| 1182 | pytester.makepyfile( |
| 1183 | myplugin=""" |
| 1184 | def pytest_collection_modifyitems(items): |
| 1185 | items[:] = sorted(items, key=lambda item: item.nodeid) |
| 1186 | print("new_items:", [x.nodeid for x in items]) |
| 1187 | """ |
| 1188 | ) |
| 1189 | pytester.syspathinsert() |
| 1190 | result = pytester.runpytest("--nf", "-p", "myplugin", "--collect-only", "-q") |
| 1191 | result.stdout.fnmatch_lines( |
| 1192 | [ |
| 1193 | "new_items: *test_1.py*test_1.py*test_2.py*", |
| 1194 | "test_1/test_1.py::test_2", |
| 1195 | "test_2/test_2.py::test_1", |
| 1196 | "test_1/test_1.py::test_1", |
| 1197 | ] |
| 1198 | ) |
| 1199 |
nothing calls this directly
no test coverage detected