@@ -1185,29 +1185,42 @@ def test_setupdecorator_and_xunit(self, pytester: Pytester) -> None:
11851185 pytester .makepyfile (
11861186 """
11871187 import pytest
1188+
11881189 values = []
1190+
11891191 @pytest.fixture(scope='module', autouse=True)
11901192 def setup_module():
11911193 values.append("module")
1194+
11921195 @pytest.fixture(autouse=True)
11931196 def setup_function():
11941197 values.append("function")
11951198
11961199 def test_func():
11971200 pass
11981201
1199- class TestClass(object) :
1202+ class TestClass:
12001203 @pytest.fixture(scope="class", autouse=True)
1201- def setup_class(self):
1204+ @classmethod
1205+ def setup_class(cls):
12021206 values.append("class")
1207+
12031208 @pytest.fixture(autouse=True)
12041209 def setup_method(self):
12051210 values.append("method")
1211+
12061212 def test_method(self):
12071213 pass
1214+
12081215 def test_all():
1209- assert values == ["module", "function", "class",
1210- "function", "method", "function"]
1216+ assert values == [
1217+ "module",
1218+ "function",
1219+ "class",
1220+ "function",
1221+ "method",
1222+ "function",
1223+ ]
12111224 """
12121225 )
12131226 reprec = pytester .inline_run ("-v" )
@@ -2467,7 +2480,8 @@ def pytest_generate_tests(metafunc):
24672480
24682481 class TestClass:
24692482 @pytest.fixture(scope="class", autouse=True)
2470- def setup_teardown(self, item):
2483+ @classmethod
2484+ def setup_teardown(cls, item):
24712485 values.append("setup-%d" % item)
24722486 yield
24732487 values.append("teardown-%d" % item)
@@ -3272,21 +3286,26 @@ def param1(request):
32723286 values = []
32733287
32743288 class TestClass(object):
3275- @classmethod
32763289 @pytest.fixture(scope="class", autouse=True)
3277- def setup1(self, request, param1):
3290+ @classmethod
3291+ def setup1(cls, request, param1):
32783292 values.append(1)
3279- request.addfinalizer(self.teardown1)
3293+ request.addfinalizer(cls.teardown1)
3294+
32803295 @classmethod
32813296 def teardown1(self):
32823297 assert values.pop() == 1
3298+
32833299 @pytest.fixture(scope="class", autouse=True)
3284- def setup2(self, request, param1):
3300+ @classmethod
3301+ def setup2(cls, request, param1):
32853302 values.append(2)
3286- request.addfinalizer(self.teardown2)
3303+ request.addfinalizer(cls.teardown2)
3304+
32873305 @classmethod
3288- def teardown2(self ):
3306+ def teardown2(cls ):
32893307 assert values.pop() == 2
3308+
32903309 def test(self):
32913310 pass
32923311
0 commit comments