Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Oct 18, 2019
1 parent 2e67d12 commit 73b9ae9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,13 @@ def _cleaning_debug(self):

if not skipped:
self._pre_setup()
super(cls, self).debug()
if not skipped:
self._post_teardown()
try:
super(cls, self).debug()
finally:
# Run _post_teardown also with SkipTest exception, when _pre_setup
# was run.
if not skipped:
self._post_teardown()

orig_debug = cls.debug
cls.debug = _cleaning_debug
Expand Down
11 changes: 7 additions & 4 deletions tests/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,13 @@ def test_method(self):
assert result.ret == 0


def test_cleaning_debug_post_teardown(django_testdir):
@pytest.mark.parametrize("skip_exc", ("unittest.SkipTest", "pytest.skip"))
def test_cleaning_debug_post_teardown_with_skipped(skip_exc, django_testdir):
p1 = django_testdir.create_test_module(
"""
from unittest import SkipTest
import unittest
import pytest
from django.test import TestCase
post_teardown_count = 0
Expand All @@ -506,11 +509,11 @@ def _post_teardown(self):
def test_1(self):
assert post_teardown_count == 0
raise SkipTest("skipped!")
raise {skip_exc}("skipped!")
def test_2(self):
assert post_teardown_count == 1
"""
""".format(skip_exc=skip_exc)
)

result = django_testdir.runpytest_subprocess(
Expand Down

0 comments on commit 73b9ae9

Please sign in to comment.