summaryrefslogtreecommitdiff
path: root/docs/internals/contributing/writing-code
diff options
context:
space:
mode:
Diffstat (limited to 'docs/internals/contributing/writing-code')
-rw-r--r--docs/internals/contributing/writing-code/unit-tests.txt44
1 files changed, 27 insertions, 17 deletions
diff --git a/docs/internals/contributing/writing-code/unit-tests.txt b/docs/internals/contributing/writing-code/unit-tests.txt
index 3690264875..d6a031b3ae 100644
--- a/docs/internals/contributing/writing-code/unit-tests.txt
+++ b/docs/internals/contributing/writing-code/unit-tests.txt
@@ -30,15 +30,17 @@ sample settings module that uses the SQLite database. To run the tests:
.. code-block:: bash
- git clone git@github.com:django/django.git django-repo
- cd django-repo/tests
- PYTHONPATH=..:$PYTHONPATH ./runtests.py
+ $ git clone git@github.com:django/django.git django-repo
+ $ cd django-repo/tests
+ $ PYTHONPATH=..:$PYTHONPATH ./runtests.py
.. versionchanged:: 1.7
-Older versions of Django required specifying a settings file::
+Older versions of Django required specifying a settings file:
- PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite
+.. code-block:: bash
+
+ $ PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite
``runtests.py`` now uses ``test_sqlite`` by default if settings aren't provided
through either ``--settings`` or :envvar:`DJANGO_SETTINGS_MODULE`.
@@ -111,7 +113,7 @@ internationalization, type:
.. code-block:: bash
- ./runtests.py --settings=path.to.settings generic_relations i18n
+ $ ./runtests.py --settings=path.to.settings generic_relations i18n
How do you find out the names of individual tests? Look in ``tests/`` — each
directory name there is the name of a test. Contrib app names are also valid
@@ -123,13 +125,13 @@ of the ``i18n`` module, type:
.. code-block:: bash
- ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests
+ $ ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests
Going beyond that, you can specify an individual test method like this:
.. code-block:: bash
- ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests.test_lazy_objects
+ $ ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests.test_lazy_objects
Running the Selenium tests
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -141,7 +143,7 @@ the tests with the ``--selenium`` option:
.. code-block:: bash
- ./runtests.py --settings=test_sqlite --selenium admin_inlines
+ $ ./runtests.py --settings=test_sqlite --selenium admin_inlines
.. _running-unit-tests-dependencies:
@@ -165,9 +167,11 @@ dependencies:
You can find these dependencies in `pip requirements files`_ inside the
``tests/requirements`` directory of the Django source tree and install them
-like so::
+like so:
- pip install -r tests/requirements/py2.txt # Python 3: py3.txt
+.. code-block:: bash
+
+ $ pip install -r tests/requirements/py2.txt # Python 3: py3.txt
You can also install the database adapter(s) of your choice using
``oracle.txt``, ``mysql.txt``, or ``postgres.txt``.
@@ -200,13 +204,17 @@ Contributors are encouraged to run coverage on the test suite to identify areas
that need additional tests. The coverage tool installation and use is described
in :ref:`testing code coverage<topics-testing-code-coverage>`.
-To run coverage on the Django test suite using the standard test settings::
+To run coverage on the Django test suite using the standard test settings:
+
+.. code-block:: bash
+
+ $ coverage run ./runtests.py --settings=test_sqlite
- coverage run ./runtests.py --settings=test_sqlite
+After running coverage, generate the html report by running:
-After running coverage, generate the html report by running::
+.. code-block:: bash
- coverage html
+ $ coverage html
When running coverage for the Django tests, the included ``.coveragerc``
settings file defines ``coverage_html`` as the output directory for the report
@@ -225,6 +233,8 @@ multiple modules by using a ``tests`` directory in the normal Python way.
If you have URLs that need to be mapped, put them in ``tests/urls.py``.
To run tests for just one contrib app (e.g. ``auth``), use the same
-method as above::
+method as above:
+
+.. code-block:: bash
- ./runtests.py --settings=settings django.contrib.auth
+ $ ./runtests.py --settings=settings django.contrib.auth