@@ -1241,12 +1241,15 @@ def test_2(self):
1241
1241
1242
1242
1243
1243
@pytest .mark .parametrize ("mark" , ["@unittest.skip" , "@pytest.mark.skip" ])
1244
- def test_pdb_teardown_skipped (
1244
+ def test_pdb_teardown_skipped_for_functions (
1245
1245
pytester : Pytester , monkeypatch : MonkeyPatch , mark : str
1246
1246
) -> None :
1247
- """With --pdb, setUp and tearDown should not be called for skipped tests."""
1247
+ """
1248
+ With --pdb, setUp and tearDown should not be called for tests skipped
1249
+ via a decorator (#7215).
1250
+ """
1248
1251
tracked : List [str ] = []
1249
- monkeypatch .setattr (pytest , "test_pdb_teardown_skipped " , tracked , raising = False )
1252
+ monkeypatch .setattr (pytest , "track_pdb_teardown_skipped " , tracked , raising = False )
1250
1253
1251
1254
pytester .makepyfile (
1252
1255
"""
@@ -1256,10 +1259,10 @@ def test_pdb_teardown_skipped(
1256
1259
class MyTestCase(unittest.TestCase):
1257
1260
1258
1261
def setUp(self):
1259
- pytest.test_pdb_teardown_skipped .append("setUp:" + self.id())
1262
+ pytest.track_pdb_teardown_skipped .append("setUp:" + self.id())
1260
1263
1261
1264
def tearDown(self):
1262
- pytest.test_pdb_teardown_skipped .append("tearDown:" + self.id())
1265
+ pytest.track_pdb_teardown_skipped .append("tearDown:" + self.id())
1263
1266
1264
1267
{mark}("skipped for reasons")
1265
1268
def test_1(self):
@@ -1274,6 +1277,43 @@ def test_1(self):
1274
1277
assert tracked == []
1275
1278
1276
1279
1280
+ @pytest .mark .parametrize ("mark" , ["@unittest.skip" , "@pytest.mark.skip" ])
1281
+ def test_pdb_teardown_skipped_for_classes (
1282
+ pytester : Pytester , monkeypatch : MonkeyPatch , mark : str
1283
+ ) -> None :
1284
+ """
1285
+ With --pdb, setUp and tearDown should not be called for tests skipped
1286
+ via a decorator on the class (#10060).
1287
+ """
1288
+ tracked : List [str ] = []
1289
+ monkeypatch .setattr (pytest , "track_pdb_teardown_skipped" , tracked , raising = False )
1290
+
1291
+ pytester .makepyfile (
1292
+ """
1293
+ import unittest
1294
+ import pytest
1295
+
1296
+ {mark}("skipped for reasons")
1297
+ class MyTestCase(unittest.TestCase):
1298
+
1299
+ def setUp(self):
1300
+ pytest.track_pdb_teardown_skipped.append("setUp:" + self.id())
1301
+
1302
+ def tearDown(self):
1303
+ pytest.track_pdb_teardown_skipped.append("tearDown:" + self.id())
1304
+
1305
+ def test_1(self):
1306
+ pass
1307
+
1308
+ """ .format (
1309
+ mark = mark
1310
+ )
1311
+ )
1312
+ result = pytester .runpytest_inprocess ("--pdb" )
1313
+ result .stdout .fnmatch_lines ("* 1 skipped in *" )
1314
+ assert tracked == []
1315
+
1316
+
1277
1317
def test_async_support (pytester : Pytester ) -> None :
1278
1318
pytest .importorskip ("unittest.async_case" )
1279
1319
0 commit comments