Skip to content

Commit a9a81b5

Browse files
author
Adam Chainz
committed
Run checks as part of database setup
1 parent 4129023 commit a9a81b5

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

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

0 commit comments

Comments
 (0)