MCPcopy
hub / github.com/pytest-dev/pytest / test_newfirst_usecase

Method test_newfirst_usecase

testing/test_cacheprovider.py:1142–1198  ·  testing/test_cacheprovider.py::TestNewFirst.test_newfirst_usecase
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

intClass · 0.85
statMethod · 0.80
fnmatch_linesMethod · 0.80
write_textMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45
syspathinsertMethod · 0.45

Tested by

no test coverage detected