Skip to content

Commit 1771cb1

Browse files
Adam Chainzadamchainz
authored andcommitted
Run checks as part of database setup
1 parent 087cbfe commit 1771cb1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

pytest_django/fixtures.py

Lines changed: 41 additions & 0 deletions
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

@@ -97,6 +99,9 @@ def django_db_setup(
9799
**setup_databases_args
98100
)
99101

102+
if get_django_version() < (1, 11):
103+
run_check(request)
104+
100105
def teardown_database():
101106
with django_db_blocker.unblock():
102107
teardown_databases(
@@ -108,6 +113,42 @@ def teardown_database():
108113
request.addfinalizer(teardown_database)
109114

110115

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

0 commit comments

Comments
 (0)