File tree 2 files changed +28
-16
lines changed 2 files changed +28
-16
lines changed Original file line number Diff line number Diff line change @@ -520,20 +520,16 @@ def _django_setup_unittest(request, django_db_blocker):
520
520
yield
521
521
return
522
522
523
- from _pytest .unittest import TestCaseFunction
523
+ # Fix/patch pytest.
524
+ # Before pytest 5.4: https://github.com/pytest-dev/pytest/issues/5991
525
+ # After pytest 5.4: https://github.com/pytest-dev/pytest-django/issues/824
526
+ from _pytest .monkeypatch import MonkeyPatch
524
527
525
- if "debug" in TestCaseFunction .runtest .__code__ .co_names :
526
- # Fix pytest (https://github.com/pytest-dev/pytest/issues/5991), only
527
- # if "self._testcase.debug()" is being used (forward compatible).
528
- from _pytest .monkeypatch import MonkeyPatch
528
+ def non_debugging_runtest (self ):
529
+ self ._testcase (result = self )
529
530
530
- def non_debugging_runtest (self ):
531
- self ._testcase (result = self )
532
-
533
- mp_debug = MonkeyPatch ()
534
- mp_debug .setattr ("_pytest.unittest.TestCaseFunction.runtest" , non_debugging_runtest )
535
- else :
536
- mp_debug = None
531
+ mp_debug = MonkeyPatch ()
532
+ mp_debug .setattr ("_pytest.unittest.TestCaseFunction.runtest" , non_debugging_runtest )
537
533
538
534
request .getfixturevalue ("django_db_setup" )
539
535
Original file line number Diff line number Diff line change @@ -58,10 +58,11 @@ def tearDown(self):
58
58
59
59
def test_sole_test (django_testdir ):
60
60
"""
61
- Make sure the database are configured when only Django TestCase classes
61
+ Make sure the database is configured when only Django TestCase classes
62
62
are collected, without the django_db marker.
63
- """
64
63
64
+ Also ensures that the DB is available after a failure (#824).
65
+ """
65
66
django_testdir .create_test_module (
66
67
"""
67
68
import os
@@ -80,12 +81,27 @@ def test_foo(self):
80
81
81
82
# Make sure it is usable
82
83
assert Item.objects.count() == 0
84
+
85
+ assert 0, "trigger_error"
86
+
87
+ class TestBar(TestCase):
88
+ def test_bar(self):
89
+ assert Item.objects.count() == 0
83
90
"""
84
91
)
85
92
86
93
result = django_testdir .runpytest_subprocess ("-v" )
87
- result .stdout .fnmatch_lines (["*TestFoo*test_foo PASSED*" ])
88
- assert result .ret == 0
94
+ result .stdout .fnmatch_lines (
95
+ [
96
+ "*::test_foo FAILED" ,
97
+ "*::test_bar PASSED" ,
98
+ '> assert 0, "trigger_error"' ,
99
+ "E AssertionError: trigger_error" ,
100
+ "E assert 0" ,
101
+ "*= 1 failed, 1 passed in *" ,
102
+ ]
103
+ )
104
+ assert result .ret == 1
89
105
90
106
91
107
class TestUnittestMethods :
You can’t perform that action at this time.
0 commit comments