Fixed #19941 -- Removed sys.path hack when running the test suite.
Thanks jezdez for the suggestion.
This commit is contained in:
parent
5ab8b5d72c
commit
c573d6de17
|
@ -32,18 +32,20 @@ sample settings module that uses the SQLite database. To run the tests:
|
||||||
|
|
||||||
git clone git@github.com:django/django.git django-repo
|
git clone git@github.com:django/django.git django-repo
|
||||||
cd django-repo/tests
|
cd django-repo/tests
|
||||||
./runtests.py
|
PYTHONPATH=..:$PYTHONPATH ./runtests.py
|
||||||
|
|
||||||
.. versionchanged:: 1.7
|
.. versionchanged:: 1.7
|
||||||
|
|
||||||
Older versions of Django required running the tests like this::
|
Older versions of Django required specifying a settings file::
|
||||||
|
|
||||||
PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite
|
PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite
|
||||||
|
|
||||||
``runtests.py`` now uses the Django package found at ``tests/../django`` (there
|
``runtests.py`` now uses ``test_sqlite`` by default if settings aren't provided
|
||||||
isn't a need to add this on your ``PYTHONPATH``) and ``test_sqlite`` for the
|
through either ``--settings`` or :envvar:`DJANGO_SETTINGS_MODULE`.
|
||||||
settings if settings aren't provided through either ``--settings`` or
|
|
||||||
:envvar:`DJANGO_SETTINGS_MODULE`.
|
You can avoid typing the ``PYTHONPATH`` bit each time by adding your Django
|
||||||
|
checkout to your ``PYTHONPATH`` or by installing the source checkout using pip.
|
||||||
|
See :ref:`installing-development-version`.
|
||||||
|
|
||||||
.. _running-unit-tests-settings:
|
.. _running-unit-tests-settings:
|
||||||
|
|
||||||
|
|
|
@ -9,21 +9,6 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
def upath(path):
|
|
||||||
"""
|
|
||||||
Separate version of django.utils._os.upath. The django.utils version isn't
|
|
||||||
usable here, as upath is needed for RUNTESTS_DIR which is needed before
|
|
||||||
django can be imported.
|
|
||||||
"""
|
|
||||||
if sys.version_info[0] != 3 and not isinstance(path, bytes):
|
|
||||||
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
|
|
||||||
return path.decode(fs_encoding)
|
|
||||||
return path
|
|
||||||
|
|
||||||
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
|
|
||||||
sys.path.insert(0, os.path.dirname(RUNTESTS_DIR)) # 'tests/../'
|
|
||||||
|
|
||||||
from django import contrib
|
from django import contrib
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
@ -33,6 +18,7 @@ CONTRIB_MODULE_PATH = 'django.contrib'
|
||||||
TEST_TEMPLATE_DIR = 'templates'
|
TEST_TEMPLATE_DIR = 'templates'
|
||||||
|
|
||||||
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
|
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
|
||||||
|
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
|
||||||
|
|
||||||
TEMP_DIR = tempfile.mkdtemp(prefix='django_')
|
TEMP_DIR = tempfile.mkdtemp(prefix='django_')
|
||||||
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
|
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
|
||||||
|
@ -99,10 +85,13 @@ def get_installed():
|
||||||
|
|
||||||
|
|
||||||
def setup(verbosity, test_labels):
|
def setup(verbosity, test_labels):
|
||||||
|
import django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models.loading import get_apps, load_app
|
from django.db.models.loading import get_apps, load_app
|
||||||
from django.test import TransactionTestCase, TestCase
|
from django.test import TransactionTestCase, TestCase
|
||||||
|
|
||||||
|
print("Testing against Django installed in '%s'" % os.path.dirname(django.__file__))
|
||||||
|
|
||||||
# Force declaring available_apps in TransactionTestCase for faster tests.
|
# Force declaring available_apps in TransactionTestCase for faster tests.
|
||||||
def no_available_apps(self):
|
def no_available_apps(self):
|
||||||
raise Exception("Please define available_apps in TransactionTestCase "
|
raise Exception("Please define available_apps in TransactionTestCase "
|
||||||
|
|
Loading…
Reference in New Issue