Skip to content

Commit

Permalink
Separates the configuration of settings into its function `configure_…
Browse files Browse the repository at this point in the history
…settings()`

Separates the configuration of settings into its function `configure_settings()`
  • Loading branch information
Montana authored Feb 11, 2024
1 parent a0762b5 commit 5d5e20d
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions testrunner.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
import os
import sys

from django.conf import settings

import django
from django.conf import settings

def runtests():
test_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, test_dir)
def configure_settings():
"""Configure Django settings for the test environment."""
base_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, base_dir)

settings.configure(
DEBUG=True,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
},
INSTALLED_APPS=('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
'experiments',),
DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3'}},
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
'experiments', # Your app to test
),
ROOT_URLCONF='experiments.tests.urls',
MIDDLEWARE = (
MIDDLEWARE=(
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware'
'django.contrib.messages.middleware.MessageMiddleware',
),
SECRET_KEY="foobarbaz",
TEMPLATES = [
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
Expand All @@ -44,15 +42,16 @@ def runtests():
},
],
)
django.setup()


def run_tests():
"""Run the Django tests for the specified apps."""
django.setup() # Initialize Django
from django.test.utils import get_runner
TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, failfast=False)
failures = test_runner.run_tests(['experiments', ])
failures = test_runner.run_tests(['experiments']) # Specify your app names here
sys.exit(bool(failures))


if __name__ == '__main__':
runtests()
configure_settings()
run_tests()

0 comments on commit 5d5e20d

Please sign in to comment.