MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_newfirst_usecase

Method test_newfirst_usecase

testing/test_cacheprovider.py:1058–1112  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

1056
1057class TestNewFirst:
1058 def test_newfirst_usecase(self, pytester: Pytester) -> None:
1059 pytester.makepyfile(
1060 **{
1061 "test_1/test_1.py": """
1062 def test_1(): assert 1
1063 """,
1064 "test_2/test_2.py": """
1065 def test_1(): assert 1
1066 """,
1067 }
1068 )
1069
1070 p1 = pytester.path.joinpath("test_1/test_1.py")
1071 os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9)))
1072
1073 result = pytester.runpytest("-v")
1074 result.stdout.fnmatch_lines(
1075 ["*test_1/test_1.py::test_1 PASSED*", "*test_2/test_2.py::test_1 PASSED*"]
1076 )
1077
1078 result = pytester.runpytest("-v", "--nf")
1079 result.stdout.fnmatch_lines(
1080 ["*test_2/test_2.py::test_1 PASSED*", "*test_1/test_1.py::test_1 PASSED*"]
1081 )
1082
1083 p1.write_text("def test_1(): assert 1\n" "def test_2(): assert 1\n")
1084 os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9)))
1085
1086 result = pytester.runpytest("--nf", "--collect-only", "-q")
1087 result.stdout.fnmatch_lines(
1088 [
1089 "test_1/test_1.py::test_2",
1090 "test_2/test_2.py::test_1",
1091 "test_1/test_1.py::test_1",
1092 ]
1093 )
1094
1095 # Newest first with (plugin) pytest_collection_modifyitems hook.
1096 pytester.makepyfile(
1097 myplugin="""
1098 def pytest_collection_modifyitems(items):
1099 items[:] = sorted(items, key=lambda item: item.nodeid)
1100 print("new_items:", [x.nodeid for x in items])
1101 """
1102 )
1103 pytester.syspathinsert()
1104 result = pytester.runpytest("--nf", "-p", "myplugin", "--collect-only", "-q")
1105 result.stdout.fnmatch_lines(
1106 [
1107 "new_items: *test_1.py*test_1.py*test_2.py*",
1108 "test_1/test_1.py::test_2",
1109 "test_2/test_2.py::test_1",
1110 "test_1/test_1.py::test_1",
1111 ]
1112 )
1113
1114 def test_newfirst_parametrize(self, pytester: Pytester) -> None:
1115 pytester.makepyfile(

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected