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

Method test_newfirst_parametrize

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

Source from the content-addressed store, hash-verified

1198 )
1199
1200 def test_newfirst_parametrize(self, pytester: Pytester) -> None:
1201 pytester.makepyfile(
1202 **{
1203 "test_1/test_1.py": """
1204 import pytest
1205 @pytest.mark.parametrize('num', [1, 2])
1206 def test_1(num): assert num
1207 """,
1208 "test_2/test_2.py": """
1209 import pytest
1210 @pytest.mark.parametrize('num', [1, 2])
1211 def test_1(num): assert num
1212 """,
1213 }
1214 )
1215
1216 p1 = pytester.path.joinpath("test_1/test_1.py")
1217 os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9)))
1218
1219 result = pytester.runpytest("-v")
1220 result.stdout.fnmatch_lines(
1221 [
1222 "*test_1/test_1.py::test_1[1*",
1223 "*test_1/test_1.py::test_1[2*",
1224 "*test_2/test_2.py::test_1[1*",
1225 "*test_2/test_2.py::test_1[2*",
1226 ]
1227 )
1228
1229 result = pytester.runpytest("-v", "--nf")
1230 result.stdout.fnmatch_lines(
1231 [
1232 "*test_2/test_2.py::test_1[1*",
1233 "*test_2/test_2.py::test_1[2*",
1234 "*test_1/test_1.py::test_1[1*",
1235 "*test_1/test_1.py::test_1[2*",
1236 ]
1237 )
1238
1239 p1.write_text(
1240 "import pytest\n"
1241 "@pytest.mark.parametrize('num', [1, 2, 3])\n"
1242 "def test_1(num): assert num\n",
1243 encoding="utf-8",
1244 )
1245 os.utime(p1, ns=(p1.stat().st_atime_ns, int(1e9)))
1246
1247 # Running only a subset does not forget about existing ones.
1248 result = pytester.runpytest("-v", "--nf", "test_2/test_2.py")
1249 result.stdout.fnmatch_lines(
1250 ["*test_2/test_2.py::test_1[1*", "*test_2/test_2.py::test_1[2*"]
1251 )
1252
1253 result = pytester.runpytest("-v", "--nf")
1254 result.stdout.fnmatch_lines(
1255 [
1256 "*test_1/test_1.py::test_1[3*",
1257 "*test_2/test_2.py::test_1[1*",

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected