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
@@ -96,6 +98,9 @@ def django_db_setup(
96
98
** setup_databases_args
97
99
)
98
100
101
+ if get_django_version () < (1 , 11 ):
102
+ run_check (request )
103
+
99
104
def teardown_database ():
100
105
with django_db_blocker .unblock ():
101
106
teardown_databases (
@@ -107,6 +112,42 @@ def teardown_database():
107
112
request .addfinalizer (teardown_database )
108
113
109
114
115
+ def run_check (request ):
116
+ from django .core .management import call_command
117
+ from django .core .management .base import SystemCheckError
118
+
119
+ # Only run once per process
120
+ if getattr (run_check , 'did_fail' , False ):
121
+ return
122
+
123
+ with disable_input_capture (request ):
124
+ try :
125
+ call_command ('check' )
126
+ except SystemCheckError as ex :
127
+ run_check .did_fail = True
128
+
129
+ if hasattr (request .config , 'slaveinput' ):
130
+ # Kill the xdist test process horribly
131
+ # N.B. 'shouldstop' maybe be obeyed properly in later as hinted at in
132
+ # https://github.com/pytest-dev/pytest-xdist/commit/e8fa73719662d1be5074a0750329fe0c35583484
133
+ print (ex .args [0 ])
134
+ sys .exit (1 )
135
+ else :
136
+ request .session .exitstatus = 1
137
+ request .session .shouldstop = True
138
+ raise
139
+
140
+
141
+ @contextmanager
142
+ def disable_input_capture (request ):
143
+ capmanager = request .config .pluginmanager .getplugin ('capturemanager' )
144
+ capmanager .suspendcapture ()
145
+ try :
146
+ yield
147
+ finally :
148
+ capmanager .resumecapture ()
149
+
150
+
110
151
def _django_db_fixture_helper (transactional , request , django_db_blocker ):
111
152
if is_django_unittest (request ):
112
153
return
0 commit comments