Skip to content

Commit

Permalink
Run test trough CustomTestRunner
Browse files Browse the repository at this point in the history
Django 1.5 uses different way to run self made test runner.
Also fix achieving database name from settings.
  • Loading branch information
ilesoft committed Nov 25, 2023
1 parent b15a827 commit fa0da99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion web/tupa/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fa0da99

Please sign in to comment.