From 83ffd627cd7f5dd97738112f2d99eae67a89c301 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 18 Oct 2019 19:09:23 +0200 Subject: [PATCH 1/2] tests: test behavior with unittest.SkipTest / teardown Ref: https://github.com/pytest-dev/pytest-django/issues/772 --- tests/test_unittest.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_unittest.py b/tests/test_unittest.py index 1f6dcd55c..523a8a061 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -495,3 +495,44 @@ def test_method(self): result = django_testdir.runpytest_subprocess("--pdb") result.stdout.fnmatch_lines(["*= 1 passed in *"]) assert result.ret == 0 + + +def test_teardown_behavior(django_testdir): + django_testdir.create_test_module( + """ + from unittest import SkipTest + from django.test import TestCase + + post_teardown_count = 0 + + class TestClass1(TestCase): + + def _post_teardown(self): + global post_teardown_count + post_teardown_count += 1 + + def test_1_skip(self): + self.addCleanup(lambda: print("clean1")) + assert post_teardown_count == 0 + raise SkipTest("skipped!") + + def test_2_pass(self): + self.addCleanup(lambda: print("clean2")) + assert post_teardown_count == 1 + + def test_3_fail(self): + self.addCleanup(lambda: print("clean3")) + assert post_teardown_count == 2 + assert 0, "fail" + """ + ) + + result = django_testdir.runpytest_subprocess("--pdb", "-s") + result.stdout.fnmatch_lines([ + "tpkg/test_the_test.py clean1", + "sclean2", + ".clean3", + "F", + "*> entering PDB >*", + "*= 1 failed, 1 passed, 1 skipped in *", + ]) From bf35558955c5166a0e5bb5feb40c39399d0ef878 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 31 Mar 2020 13:50:56 +0200 Subject: [PATCH 2/2] skip py27 --- tests/test_unittest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_unittest.py b/tests/test_unittest.py index 523a8a061..8159c7b57 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -1,4 +1,5 @@ import pytest +import sys from django.test import TestCase from pytest_django.plugin import _pytest_version_info @@ -497,6 +498,7 @@ def test_method(self): assert result.ret == 0 +@pytest.mark.skipif(sys.version_info < (3,), reason="py27: no print function") def test_teardown_behavior(django_testdir): django_testdir.create_test_module( """