Skip to content

Commit 017693a

Browse files
Adam Chainzadamchainz
Adam Chainz
authored andcommitted
Run checks as part of database setup
1 parent 6cbb84f commit 017693a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

pytest_django/fixtures.py

+41
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from __future__ import with_statement
44

55
import os
6+
import sys
7+
from contextlib import contextmanager
68

79
import pytest
810

@@ -99,6 +101,9 @@ def django_db_setup(
99101
**setup_databases_args
100102
)
101103

104+
if get_django_version() < (1, 11):
105+
run_check(request)
106+
102107
def teardown_database():
103108
with django_db_blocker.unblock():
104109
teardown_databases(
@@ -110,6 +115,42 @@ def teardown_database():
110115
request.addfinalizer(teardown_database)
111116

112117

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+
113154
def _django_db_fixture_helper(transactional, request, django_db_blocker):
114155
if is_django_unittest(request):
115156
return

0 commit comments

Comments
 (0)