Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] tests: test behavior with unittest.SkipTest #775

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/test_unittest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import sys
from django.test import TestCase

from pytest_django.plugin import _pytest_version_info
Expand Down Expand Up @@ -495,3 +496,45 @@ def test_method(self):
result = django_testdir.runpytest_subprocess("--pdb")
result.stdout.fnmatch_lines(["*= 1 passed in *"])
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(
"""
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 *",
])