From d7bb07ad4468d738f5ba321ee730921f3886e5a3 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 26 Feb 2016 16:24:09 -0800 Subject: Fix premature file delete on DEBUG=False. Modify test runner to check both DEBUG options. --- wkhtmltopdf/tests/run.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'wkhtmltopdf/tests/run.py') diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py index 5004ee1..b969a29 100644 --- a/wkhtmltopdf/tests/run.py +++ b/wkhtmltopdf/tests/run.py @@ -9,6 +9,26 @@ DIRNAME = os.path.abspath(os.path.dirname(__file__)) sys.path.insert(0, os.getcwd()) +def run_tests(): + # Utility function to executes tests. + # Will be called twice. Once with DEBUG=True and once with DEBUG=False. + try: + django.setup() + except AttributeError: + pass # Django < 1.7; okay to ignore + + + try: + from django.test.runner import DiscoverRunner + except ImportError: + from discover_runner.runner import DiscoverRunner + + + test_runner = DiscoverRunner(verbosity=1) + failures = test_runner.run_tests(['wkhtmltopdf']) + if failures: + sys.exit(1) + settings.configure( DEBUG=True, DATABASES={ @@ -32,19 +52,11 @@ settings.configure( WKHTMLTOPDF_DEBUG=True, ) -try: - django.setup() -except AttributeError: - pass # Django < 1.7; okay to ignore - - -try: - from django.test.runner import DiscoverRunner -except ImportError: - from discover_runner.runner import DiscoverRunner +# Run tests with True debug settings (persistent temporary files). +run_tests() +settings.DEBUG = False +settings.WKHTMLTOPDF_DEBUG = False -test_runner = DiscoverRunner(verbosity=1) -failures = test_runner.run_tests(['wkhtmltopdf']) -if failures: - sys.exit(1) +# Run tests with False debug settings to test temporary file delete operations. +run_tests() -- cgit v1.2.3