3
3
from __future__ import with_statement
4
4
5
5
import os
6
+ import sys
7
+ from contextlib import contextmanager
6
8
7
9
import pytest
8
10
@@ -99,6 +101,9 @@ def django_db_setup(
99
101
** setup_databases_args
100
102
)
101
103
104
+ if get_django_version () < (1 , 11 ):
105
+ run_check (request )
106
+
102
107
def teardown_database ():
103
108
with django_db_blocker .unblock ():
104
109
teardown_databases (
@@ -110,6 +115,42 @@ def teardown_database():
110
115
request .addfinalizer (teardown_database )
111
116
112
117
118
+ def run_check (request ):
119
+ from django .core .management import call_command
120
+ from django .core .management .base import SystemCheckError
121
+
122
+ # Only run once per process
123
+ if getattr (run_check , 'did_fail' , False ):
124
+ return
125
+
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
142
+
143
+
144
+ @contextmanager
145
+ def disable_input_capture (request ):
146
+ capmanager = request .config .pluginmanager .getplugin ('capturemanager' )
147
+ capmanager .suspendcapture ()
148
+ try :
149
+ yield
150
+ finally :
151
+ capmanager .resumecapture ()
152
+
153
+
113
154
def _django_db_fixture_helper (transactional , request , django_db_blocker ):
114
155
if is_django_unittest (request ):
115
156
return
0 commit comments