From fa0da99b622da18985ad34e229099a922eb4010d Mon Sep 17 00:00:00 2001 From: Ile Date: Sat, 25 Nov 2023 11:13:46 +0200 Subject: [PATCH] Run test trough CustomTestRunner Django 1.5 uses different way to run self made test runner. Also fix achieving database name from settings. --- web/settings/__init__.py | 2 +- web/tupa/tests.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/web/settings/__init__.py b/web/settings/__init__.py index 13d7dc1c..81dfc547 100644 --- a/web/settings/__init__.py +++ b/web/settings/__init__.py @@ -108,7 +108,7 @@ LOGIN_URL = ('/kipa/') LOGIN_REDIRECT_URL = ('/kipa/') -TEST_RUNNER = ('tupa.tests') +TEST_RUNNER = ('tupa.tests.CustomTestRunner') # Should we serve the media files through Python? SERVE_MEDIA = DEBUG diff --git a/web/tupa/tests.py b/web/tupa/tests.py index 6196ebb3..c77080fe 100644 --- a/web/tupa/tests.py +++ b/web/tupa/tests.py @@ -8,6 +8,7 @@ from taulukkolaskin import * import decimal from django.test import TestCase +from django.test.simple import DjangoTestSuiteRunner from views import * import os from django.test.client import Client @@ -307,6 +308,10 @@ def testJarjestys(self): assert tulokset[0][5][0].nro==5 assert tulokset[0][6][0].nro==6 +class CustomTestRunner(DjangoTestSuiteRunner): + def run_tests(self, test_labels=None, extra_tests=None, verbosity=1, interactive=True, failfast=True, **kwargs): + run_one_fixture(test_labels, verbosity, interactive, extra_tests) + def run_one_fixture(test_labels, verbosity=1, interactive=True, extra_tests=[]): #ajetaan vain haluttu fixtuuri # Nollataan fixturet @@ -401,7 +406,7 @@ def run_one_fixture(test_labels, verbosity=1, interactive=True, extra_tests=[]): suites.append(unittest.TestLoader().loadTestsFromTestCase(t)) suite=unittest.TestSuite(suites) - old_name = settings.DATABASE_NAME + old_name = settings.DATABASES["default"]["NAME"] from django.db import connection connection.creation.create_test_db(verbosity, autoclobber=not interactive) result = unittest.TextTestRunner(verbosity=verbosity).run(suite)