Skip to content

Commit

Permalink
tests: test behavior with unittest.SkipTest / teardown
Browse files Browse the repository at this point in the history
Ref: #772
  • Loading branch information
blueyed committed Mar 31, 2020
1 parent ee7858a commit 83ffd62
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *",
])

0 comments on commit 83ffd62

Please sign in to comment.