Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #19941 -- Modified to make running the tests easier.

1. Automatically use tests/../django as the Django version.
2. If settings aren't provided through --settings or DJANGO_SETTINGS_MODULE)
   then use test_sqlite.
  • Loading branch information...
1 parent 372158a commit b2314d9e1e08749f2c05151f9cd44520d2b3a03a @akaariai akaariai committed with timgraham
16 docs/internals/contributing/writing-code/unit-tests.txt
@@ -25,16 +25,26 @@ Quickstart
Running the tests requires a Django settings module that defines the
-databases to use. To make it easy to get started, Django provides a
-sample settings module that uses the SQLite database. To run the tests
-with this sample ``settings`` module:
+databases to use. To make it easy to get started, Django provides and uses a
+sample settings module that uses the SQLite database. To run the tests:
.. code-block:: bash
git clone django-repo
cd django-repo/tests
+ ./
+.. versionchanged:: 1.7
+Older versions of Django required running the tests like this::
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
.. _running-unit-tests-settings:
Using another ``settings`` module
20 tests/
@@ -7,6 +7,20 @@
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
@@ -15,7 +29,6 @@
TEST_TEMPLATE_DIR = 'templates'
-RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
TEMP_DIR = tempfile.mkdtemp(prefix='django_')
@@ -331,10 +344,9 @@ def paired_tests(paired_test, options, test_labels):
options, args = parser.parse_args()
if options.settings:
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
- elif "DJANGO_SETTINGS_MODULE" not in os.environ:
- parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. "
- "Set it or use --settings.")
+ if "DJANGO_SETTINGS_MODULE" not in os.environ:
+ os.environ['DJANGO_SETTINGS_MODULE'] = 'test_sqlite'
options.settings = os.environ['DJANGO_SETTINGS_MODULE']
if options.liveserver is not None:

0 comments on commit b2314d9

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