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