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

Method test_newfirst_parametrize

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

Source from the content-addressed store, hash-verified

1112 )
1113
1114 def test_newfirst_parametrize(self, pytester: Pytester) -> None:
1115 pytester.makepyfile(
1116 **{
1117 "test_1/test_1.py": """
1118 import pytest
1119 @pytest.mark.parametrize('num', [1, 2])
1120 def test_1(num): assert num
1121 """,
1122 "test_2/test_2.py": """
1123 import pytest
1124 @pytest.mark.parametrize('num', [1, 2])
1125 def test_1(num): assert num
1126 """,
1127 }
1128 )
1129
1130 p1 = pytester.path.joinpath("test_1/test_1.py")
1131 os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9)))
1132
1133 result = pytester.runpytest("-v")
1134 result.stdout.fnmatch_lines(
1135 [
1136 "*test_1/test_1.py::test_1[1*",
1137 "*test_1/test_1.py::test_1[2*",
1138 "*test_2/test_2.py::test_1[1*",
1139 "*test_2/test_2.py::test_1[2*",
1140 ]
1141 )
1142
1143 result = pytester.runpytest("-v", "--nf")
1144 result.stdout.fnmatch_lines(
1145 [
1146 "*test_2/test_2.py::test_1[1*",
1147 "*test_2/test_2.py::test_1[2*",
1148 "*test_1/test_1.py::test_1[1*",
1149 "*test_1/test_1.py::test_1[2*",
1150 ]
1151 )
1152
1153 p1.write_text(
1154 "import pytest\n"
1155 "@pytest.mark.parametrize('num', [1, 2, 3])\n"
1156 "def test_1(num): assert num\n"
1157 )
1158 os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9)))
1159
1160 # Running only a subset does not forget about existing ones.
1161 result = pytester.runpytest("-v", "--nf", "test_2/test_2.py")
1162 result.stdout.fnmatch_lines(
1163 ["*test_2/test_2.py::test_1[1*", "*test_2/test_2.py::test_1[2*"]
1164 )
1165
1166 result = pytester.runpytest("-v", "--nf")
1167 result.stdout.fnmatch_lines(
1168 [
1169 "*test_1/test_1.py::test_1[3*",
1170 "*test_2/test_2.py::test_1[1*",
1171 "*test_2/test_2.py::test_1[2*",

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected