5
5
import os
6
6
import sys
7
7
from contextlib import contextmanager
8
+ from io import BytesIO
8
9
9
10
import pytest
10
11
@@ -99,8 +100,7 @@ def django_db_setup(
99
100
** setup_databases_args
100
101
)
101
102
102
- if get_django_version () < (1 , 11 ):
103
- run_check (request )
103
+ run_checks (request )
104
104
105
105
def teardown_database ():
106
106
with django_db_blocker .unblock ():
@@ -113,30 +113,31 @@ def teardown_database():
113
113
request .addfinalizer (teardown_database )
114
114
115
115
116
- def run_check (request ):
116
+ def run_checks (request ):
117
117
from django .core .management import call_command
118
118
from django .core .management .base import SystemCheckError
119
119
120
120
# Only run once per process
121
- if getattr (run_check , 'did_fail ' , False ):
121
+ if getattr (run_checks , 'ran ' , False ):
122
122
return
123
+ run_checks .ran = True
123
124
124
- with disable_input_capture ( request ):
125
- try :
126
- call_command ('check' )
127
- except SystemCheckError as ex :
128
- run_check . did_fail = True
129
-
130
- if hasattr (request .config , 'slaveinput' ):
131
- # Kill the xdist test process horribly
132
- # N.B. 'shouldstop' maybe be obeyed properly in later as hinted at in
133
- # https://github.com/pytest-dev/pytest-xdist/commit/e8fa73719662d1be5074a0750329fe0c35583484
134
- print (ex .args [0 ])
135
- sys .exit (1 )
136
- else :
137
- request . session . exitstatus = 1
138
- request .session .shouldstop = True
139
- raise
125
+ out = BytesIO ()
126
+ try :
127
+ call_command ('check' , out = out , err = out )
128
+ except SystemCheckError as ex :
129
+ run_checks . exc = ex
130
+
131
+ if hasattr (request .config , 'slaveinput' ):
132
+ # Kill the xdist test process horribly
133
+ # N.B. 'shouldstop' may be obeyed properly in the future as hinted at in
134
+ # https://github.com/pytest-dev/pytest-xdist/commit/e8fa73719662d1be5074a0750329fe0c35583484
135
+ print (ex .args [0 ])
136
+ sys .exit (1 )
137
+ else :
138
+ # Ensure we get the EXIT_TESTSFAILED exit code
139
+ request .session .testsfailed += 1
140
+ request . session . shouldstop = True
140
141
141
142
142
143
@contextmanager
0 commit comments