Skip to content

Commit

Permalink
Run checks as part of database setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Chainz committed Nov 5, 2016
1 parent 4129023 commit a9a81b5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from __future__ import with_statement

import os
import sys
from contextlib import contextmanager

import pytest

Expand Down Expand Up @@ -96,6 +98,9 @@ def django_db_setup(
**setup_databases_args
)

if get_django_version() < (1, 11):
run_check(request)

def teardown_database():
with django_db_blocker.unblock():
teardown_databases(
Expand All @@ -107,6 +112,42 @@ def teardown_database():
request.addfinalizer(teardown_database)


def run_check(request):
from django.core.management import call_command
from django.core.management.base import SystemCheckError

# Only run once per process
if getattr(run_check, 'did_fail', False):
return

with disable_input_capture(request):
try:
call_command('check')
except SystemCheckError as ex:
run_check.did_fail = True

if hasattr(request.config, 'slaveinput'):
# Kill the xdist test process horribly
# N.B. 'shouldstop' maybe be obeyed properly in later as hinted at in
# https://github.com/pytest-dev/pytest-xdist/commit/e8fa73719662d1be5074a0750329fe0c35583484
print(ex.args[0])
sys.exit(1)
else:
request.session.exitstatus = 1
request.session.shouldstop = True
raise


@contextmanager
def disable_input_capture(request):
capmanager = request.config.pluginmanager.getplugin('capturemanager')
capmanager.suspendcapture()
try:
yield
finally:
capmanager.resumecapture()


def _django_db_fixture_helper(transactional, request, django_db_blocker):
if is_django_unittest(request):
return
Expand Down

0 comments on commit a9a81b5

Please sign in to comment.