@@ -953,181 +953,6 @@ def test_fun2(keywords):
953953 reprec .assertoutcome (passed = 2 )
954954
955955
956- class TestRequestCachedSetup (object ):
957- def test_request_cachedsetup_defaultmodule (self , testdir ):
958- reprec = testdir .inline_runsource (
959- """
960- mysetup = ["hello",].pop
961-
962- import pytest
963-
964- @pytest.fixture
965- def something(request):
966- return request.cached_setup(mysetup, scope="module")
967-
968- def test_func1(something):
969- assert something == "hello"
970- class TestClass(object):
971- def test_func1a(self, something):
972- assert something == "hello"
973- """ ,
974- SHOW_PYTEST_WARNINGS_ARG ,
975- )
976- reprec .assertoutcome (passed = 2 )
977-
978- def test_request_cachedsetup_class (self , testdir ):
979- reprec = testdir .inline_runsource (
980- """
981- mysetup = ["hello", "hello2", "hello3"].pop
982-
983- import pytest
984- @pytest.fixture
985- def something(request):
986- return request.cached_setup(mysetup, scope="class")
987- def test_func1(something):
988- assert something == "hello3"
989- def test_func2(something):
990- assert something == "hello2"
991- class TestClass(object):
992- def test_func1a(self, something):
993- assert something == "hello"
994- def test_func2b(self, something):
995- assert something == "hello"
996- """ ,
997- SHOW_PYTEST_WARNINGS_ARG ,
998- )
999- reprec .assertoutcome (passed = 4 )
1000-
1001- @pytest .mark .filterwarnings ("ignore:cached_setup is deprecated" )
1002- def test_request_cachedsetup_extrakey (self , testdir ):
1003- item1 = testdir .getitem ("def test_func(): pass" )
1004- req1 = fixtures .FixtureRequest (item1 )
1005- values = ["hello" , "world" ]
1006-
1007- def setup ():
1008- return values .pop ()
1009-
1010- ret1 = req1 .cached_setup (setup , extrakey = 1 )
1011- ret2 = req1 .cached_setup (setup , extrakey = 2 )
1012- assert ret2 == "hello"
1013- assert ret1 == "world"
1014- ret1b = req1 .cached_setup (setup , extrakey = 1 )
1015- ret2b = req1 .cached_setup (setup , extrakey = 2 )
1016- assert ret1 == ret1b
1017- assert ret2 == ret2b
1018-
1019- @pytest .mark .filterwarnings ("ignore:cached_setup is deprecated" )
1020- def test_request_cachedsetup_cache_deletion (self , testdir ):
1021- item1 = testdir .getitem ("def test_func(): pass" )
1022- req1 = fixtures .FixtureRequest (item1 )
1023- values = []
1024-
1025- def setup ():
1026- values .append ("setup" )
1027-
1028- def teardown (val ):
1029- values .append ("teardown" )
1030-
1031- req1 .cached_setup (setup , teardown , scope = "function" )
1032- assert values == ["setup" ]
1033- # artificial call of finalizer
1034- setupstate = req1 ._pyfuncitem .session ._setupstate
1035- setupstate ._callfinalizers (item1 )
1036- assert values == ["setup" , "teardown" ]
1037- req1 .cached_setup (setup , teardown , scope = "function" )
1038- assert values == ["setup" , "teardown" , "setup" ]
1039- setupstate ._callfinalizers (item1 )
1040- assert values == ["setup" , "teardown" , "setup" , "teardown" ]
1041-
1042- def test_request_cached_setup_two_args (self , testdir ):
1043- testdir .makepyfile (
1044- """
1045- import pytest
1046-
1047- @pytest.fixture
1048- def arg1(request):
1049- return request.cached_setup(lambda: 42)
1050- @pytest.fixture
1051- def arg2(request):
1052- return request.cached_setup(lambda: 17)
1053- def test_two_different_setups(arg1, arg2):
1054- assert arg1 != arg2
1055- """
1056- )
1057- result = testdir .runpytest ("-v" , SHOW_PYTEST_WARNINGS_ARG )
1058- result .stdout .fnmatch_lines (["*1 passed*" ])
1059-
1060- def test_request_cached_setup_getfixturevalue (self , testdir ):
1061- testdir .makepyfile (
1062- """
1063- import pytest
1064-
1065- @pytest.fixture
1066- def arg1(request):
1067- arg1 = request.getfixturevalue("arg2")
1068- return request.cached_setup(lambda: arg1 + 1)
1069- @pytest.fixture
1070- def arg2(request):
1071- return request.cached_setup(lambda: 10)
1072- def test_two_funcarg(arg1):
1073- assert arg1 == 11
1074- """
1075- )
1076- result = testdir .runpytest ("-v" , SHOW_PYTEST_WARNINGS_ARG )
1077- result .stdout .fnmatch_lines (["*1 passed*" ])
1078-
1079- def test_request_cached_setup_functional (self , testdir ):
1080- testdir .makepyfile (
1081- test_0 = """
1082- import pytest
1083- values = []
1084- @pytest.fixture
1085- def something(request):
1086- val = request.cached_setup(fsetup, fteardown)
1087- return val
1088- def fsetup(mycache=[1]):
1089- values.append(mycache.pop())
1090- return values
1091- def fteardown(something):
1092- values.remove(something[0])
1093- values.append(2)
1094- def test_list_once(something):
1095- assert something == [1]
1096- def test_list_twice(something):
1097- assert something == [1]
1098- """
1099- )
1100- testdir .makepyfile (
1101- test_1 = """
1102- import test_0 # should have run already
1103- def test_check_test0_has_teardown_correct():
1104- assert test_0.values == [2]
1105- """
1106- )
1107- result = testdir .runpytest ("-v" , SHOW_PYTEST_WARNINGS_ARG )
1108- result .stdout .fnmatch_lines (["*3 passed*" ])
1109-
1110- def test_issue117_sessionscopeteardown (self , testdir ):
1111- testdir .makepyfile (
1112- """
1113- import pytest
1114-
1115- @pytest.fixture
1116- def app(request):
1117- app = request.cached_setup(
1118- scope='session',
1119- setup=lambda: 0,
1120- teardown=lambda x: 3/x)
1121- return app
1122- def test_func(app):
1123- pass
1124- """
1125- )
1126- result = testdir .runpytest (SHOW_PYTEST_WARNINGS_ARG )
1127- assert result .ret != 0
1128- result .stdout .fnmatch_lines (["*3/x*" , "*ZeroDivisionError*" ])
1129-
1130-
1131956class TestFixtureUsages (object ):
1132957 def test_noargfixturedec (self , testdir ):
1133958 testdir .makepyfile (
@@ -2297,15 +2122,7 @@ def test_4(arg, created, finalized):
22972122 reprec = testdir .inline_run ()
22982123 reprec .assertoutcome (passed = 4 )
22992124
2300- @pytest .mark .parametrize (
2301- "method" ,
2302- [
2303- 'request.getfixturevalue("arg")' ,
2304- 'request.cached_setup(lambda: None, scope="function")' ,
2305- ],
2306- ids = ["getfixturevalue" , "cached_setup" ],
2307- )
2308- def test_scope_mismatch_various (self , testdir , method ):
2125+ def test_scope_mismatch_various (self , testdir ):
23092126 testdir .makeconftest (
23102127 """
23112128 import pytest
@@ -2321,11 +2138,10 @@ def arg(request):
23212138 import pytest
23222139 @pytest.fixture(scope="session")
23232140 def arg(request):
2324- %s
2141+ request.getfixturevalue("arg")
23252142 def test_1(arg):
23262143 pass
23272144 """
2328- % method
23292145 )
23302146 result = testdir .runpytest (SHOW_PYTEST_WARNINGS_ARG )
23312147 assert result .ret != 0
0 commit comments