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