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

Method test_parametrize_class_scenarios

testing/python/metafunc.py:930–970  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

928 reprec.assertoutcome(passed=2)
929
930 def test_parametrize_class_scenarios(self, pytester: Pytester) -> None:
931 pytester.makepyfile(
932 """
933 # same as doc/en/example/parametrize scenario example
934 def pytest_generate_tests(metafunc):
935 idlist = []
936 argvalues = []
937 for scenario in metafunc.cls.scenarios:
938 idlist.append(scenario[0])
939 items = scenario[1].items()
940 argnames = [x[0] for x in items]
941 argvalues.append(([x[1] for x in items]))
942 metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class")
943
944 class Test(object):
945 scenarios = [['1', {'arg': {1: 2}, "arg2": "value2"}],
946 ['2', {'arg':'value2', "arg2": "value2"}]]
947
948 def test_1(self, arg, arg2):
949 pass
950
951 def test_2(self, arg2, arg):
952 pass
953
954 def test_3(self, arg, arg2):
955 pass
956 """
957 )
958 result = pytester.runpytest("-v")
959 assert result.ret == 0
960 result.stdout.fnmatch_lines(
961 """
962 *test_1*1*
963 *test_2*1*
964 *test_3*1*
965 *test_1*2*
966 *test_2*2*
967 *test_3*2*
968 *6 passed*
969 """
970 )
971
972 def test_format_args(self) -> None:
973 def function1():

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected