From 73b9ae9aa04328f5de0638ed70572b4d19126ce9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 18 Oct 2019 20:16:54 +0200 Subject: [PATCH] fix --- pytest_django/plugin.py | 10 +++++++--- tests/test_unittest.py | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 07cc88fe3..5e49cc1b2 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -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 diff --git a/tests/test_unittest.py b/tests/test_unittest.py index a64605727..cd28a8fca 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -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 @@ -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(