Skip to content

Commit

Permalink
Store temporary variables on config rather than function
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed May 27, 2018
1 parent 182f0ba commit 7aa1ea0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,24 @@ def run_checks(request):
from django.core.management import call_command
from django.core.management.base import SystemCheckError

config = request.config

# Only run once per process
if getattr(run_checks, 'ran', False):
if getattr(config, '_pytest_django_checks_ran', False):
return
run_checks.ran = True
config._pytest_django_checks_ran = True

out = StringIO()
try:
call_command('check', stdout=out, stderr=out)
except SystemCheckError as ex:
run_checks.exc = ex
except SystemCheckError as exc:
config._pytest_django_checks_exc = exc

if hasattr(request.config, 'slaveinput'):
# Kill the xdist test process horribly
# N.B. 'shouldstop' may be obeyed properly in the future as hinted at in
# https://github.com/pytest-dev/pytest-xdist/commit/e8fa73719662d1be5074a0750329fe0c35583484
print(ex.args[0])
print(exc.args[0])
sys.exit(1)
else:
# Ensure we get the EXIT_TESTSFAILED exit code
Expand Down
3 changes: 2 additions & 1 deletion pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def pytest_runtest_setup(item):


def pytest_terminal_summary(terminalreporter, exitstatus):
check_exc = getattr(run_checks, 'exc', None)
config = terminalreporter.config
check_exc = getattr(config, '_pytest_django_checks_exc', None)
if check_exc:
terminalreporter.write('\n')
terminalreporter.write(str(check_exc))
Expand Down

0 comments on commit 7aa1ea0

Please sign in to comment.