Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #19941 -- Removed sys.path hack when running the test suite.

Thanks jezdez for the suggestion.
  • Loading branch information...
1 parent 5ab8b5d commit c573d6de173c0e6743473081cde786e749641a48 @timgraham timgraham committed
14 docs/internals/contributing/writing-code/unit-tests.txt
@@ -32,18 +32,20 @@ sample settings module that uses the SQLite database. To run the tests:
git clone django-repo
cd django-repo/tests
- ./
.. 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 ./ --settings=test_sqlite
-```` now uses the Django package found at ``tests/../django`` (there
-isn't a need to add this on your ``PYTHONPATH``) and ``test_sqlite`` for the
-settings if settings aren't provided through either ``--settings`` or
+```` now uses ``test_sqlite`` by default 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:
19 tests/
@@ -9,21 +9,6 @@
import tempfile
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.utils._os import upath
from django.utils import six
@@ -33,6 +18,7 @@ def upath(path):
TEST_TEMPLATE_DIR = 'templates'
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
+RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
TEMP_DIR = tempfile.mkdtemp(prefix='django_')
@@ -99,10 +85,13 @@ def get_installed():
def setup(verbosity, test_labels):
+ import django
from django.conf import settings
from django.db.models.loading import get_apps, load_app
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.
def no_available_apps(self):
raise Exception("Please define available_apps in TransactionTestCase "

0 comments on commit c573d6d

Please sign in to comment.
Something went wrong with that request. Please try again.