Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separates the configuration of settings into its function. #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading