Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def setup(self):

def teardown(self):
if self._explicit_tearDown is not None:
self._explicit_tearDown()
if not self._store.get(skipped_by_mark_key, False):
self._explicit_tearDown()
self._explicit_tearDown = None
self._testcase = None
self._obj = None
Expand Down
56 changes: 56 additions & 0 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,62 @@ def test_2(self):
]


def test_unittest_skip_method_does_not_call_teardown_with_pdb(testdir):
testdir.makepyfile(
"""
import unittest

class MyTestCase(unittest.TestCase):
@unittest.skip("skip method")
def test_skipped(self):
pass

def tearDown(self):
raise AssertionError("tearDown should not be called")
"""
)
result = testdir.runpytest_inprocess("--pdb")
result.assert_outcomes(skipped=1)


def test_unittest_setUp_raises_SkipTest_does_not_call_teardown_with_pdb(testdir):
testdir.makepyfile(
"""
import unittest

class MyTestCase(unittest.TestCase):
def setUp(self):
raise unittest.SkipTest("skip in setup")

def tearDown(self):
raise AssertionError("tearDown should not be called")

def test_something(self):
pass
"""
)
result = testdir.runpytest_inprocess("--pdb")
result.assert_outcomes(skipped=1)


def test_unittest_class_skip_does_not_call_teardown_with_pdb(testdir):
testdir.makepyfile(
"""
import unittest

@unittest.skip("skip class")
class MyTestCase(unittest.TestCase):
def tearDown(self):
raise AssertionError("tearDown should not be called")

def test_something(self):
pass
"""
)
result = testdir.runpytest_inprocess("--pdb")
result.assert_outcomes(skipped=1)


def test_async_support(testdir):
pytest.importorskip("unittest.async_case")

Expand Down