Skip to content

Commit 73b9ae9

Browse files
committed
fix
1 parent 2e67d12 commit 73b9ae9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pytest_django/plugin.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,13 @@ def _cleaning_debug(self):
535535

536536
if not skipped:
537537
self._pre_setup()
538-
super(cls, self).debug()
539-
if not skipped:
540-
self._post_teardown()
538+
try:
539+
super(cls, self).debug()
540+
finally:
541+
# Run _post_teardown also with SkipTest exception, when _pre_setup
542+
# was run.
543+
if not skipped:
544+
self._post_teardown()
541545

542546
orig_debug = cls.debug
543547
cls.debug = _cleaning_debug

tests/test_unittest.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,13 @@ def test_method(self):
489489
assert result.ret == 0
490490

491491

492-
def test_cleaning_debug_post_teardown(django_testdir):
492+
@pytest.mark.parametrize("skip_exc", ("unittest.SkipTest", "pytest.skip"))
493+
def test_cleaning_debug_post_teardown_with_skipped(skip_exc, django_testdir):
493494
p1 = django_testdir.create_test_module(
494495
"""
495-
from unittest import SkipTest
496+
import unittest
497+
498+
import pytest
496499
from django.test import TestCase
497500
498501
post_teardown_count = 0
@@ -506,11 +509,11 @@ def _post_teardown(self):
506509
507510
def test_1(self):
508511
assert post_teardown_count == 0
509-
raise SkipTest("skipped!")
512+
raise {skip_exc}("skipped!")
510513
511514
def test_2(self):
512515
assert post_teardown_count == 1
513-
"""
516+
""".format(skip_exc=skip_exc)
514517
)
515518

516519
result = django_testdir.runpytest_subprocess(

0 commit comments

Comments
 (0)