Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Thanks jezdez for the suggestion.
  • Loading branch information...
commit c573d6de173c0e6743473081cde786e749641a48 1 parent 5ab8b5d
@timgraham timgraham authored
View
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 git@github.com:django/django.git django-repo
cd django-repo/tests
- ./runtests.py
+ PYTHONPATH=..:$PYTHONPATH ./runtests.py
.. 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
-``runtests.py`` 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
-:envvar:`DJANGO_SETTINGS_MODULE`.
+``runtests.py`` 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:
View
19 tests/runtests.py
@@ -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_')
os.environ['DJANGO_TEST_TEMP_DIR'] = TEMP_DIR
@@ -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 "
Please sign in to comment.
Something went wrong with that request. Please try again.