33from __future__ import with_statement
44
55import os
6+ import sys
7+ from contextlib import contextmanager
68
79import pytest
810
@@ -96,6 +98,9 @@ def django_db_setup(
9698 ** setup_databases_args
9799 )
98100
101+ if get_django_version () < (1 , 11 ):
102+ run_check (request )
103+
99104 def teardown_database ():
100105 with django_db_blocker .unblock ():
101106 teardown_databases (
@@ -107,6 +112,42 @@ def teardown_database():
107112 request .addfinalizer (teardown_database )
108113
109114
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+
110151def _django_db_fixture_helper (transactional , request , django_db_blocker ):
111152 if is_django_unittest (request ):
112153 return
0 commit comments