@@ -45,6 +45,73 @@ See :ref:`installing-development-version`.
45
45
46
46
Having problems? See :ref:`troubleshooting-unit-tests` for some common issues.
47
47
48
+ Running tests using ``tox``
49
+ ---------------------------
50
+
51
+ `Tox <http://tox.testrun.org/>`_ is a tool for running tests in different
52
+ virtual environments. Django includes a basic ``tox.ini`` that automates some
53
+ checks that our build server performs on pull requests. To run the unit tests
54
+ and other checks (such as :ref:`import sorting <coding-style-imports>`, the
55
+ :ref:`documentation spelling checker <documentation-spelling-check>`, and
56
+ :ref:`code formatting <coding-style-python>`), install and run the ``tox``
57
+ command from any place in the Django source tree::
58
+
59
+ $ pip install tox
60
+ $ tox
61
+
62
+ By default, ``tox`` runs the test suite with the bundled test settings file for
63
+ SQLite, ``flake8``, ``isort``, and the documentation spelling checker. In
64
+ addition to the system dependencies noted elsewhere in this documentation,
65
+ the commands ``python2`` and ``python3`` must be on your path and linked to
66
+ the appropriate versions of Python. A list of default environments can be seen
67
+ as follows::
68
+
69
+ $ tox -l
70
+ py3
71
+ flake8
72
+ docs
73
+ isort
74
+
75
+ Testing other Python versions and database backends
76
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77
+
78
+ In addition to the default environments, ``tox`` supports running unit tests
79
+ for other versions of Python and other database backends. Since Django's test
80
+ suite doesn't bundle a settings file for database backends other than SQLite,
81
+ however, you must :ref:`create and provide your own test settings
82
+ <running-unit-tests-settings>`. For example, to run the tests on Python 3.5
83
+ using PostgreSQL::
84
+
85
+ $ tox -e py35-postgres -- --settings=my_postgres_settings
86
+
87
+ This command sets up a Python 3.5 virtual environment, installs Django's
88
+ test suite dependencies (including those for PostgreSQL), and calls
89
+ ``runtests.py`` with the supplied arguments (in this case,
90
+ ``--settings=my_postgres_settings``).
91
+
92
+ The remainder of this documentation shows commands for running tests without
93
+ ``tox``, however, any option passed to ``runtests.py`` can also be passed to
94
+ ``tox`` by prefixing the argument list with ``--``, as above.
95
+
96
+ Tox also respects the ``DJANGO_SETTINGS_MODULE`` environment variable, if set.
97
+ For example, the following is equivalent to the command above::
98
+
99
+ $ DJANGO_SETTINGS_MODULE=my_postgres_settings tox -e py35-postgres
100
+
101
+ Running the JavaScript tests
102
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
+
104
+ Django includes a set of :ref:`JavaScript unit tests <javascript-tests>` for
105
+ functions in certain contrib apps. The JavaScript tests aren't run by default
106
+ using ``tox`` because they require `Node.js` to be installed and aren't
107
+ necessary for the majority of patches. To run the JavaScript tests using
108
+ ``tox``::
109
+
110
+ $ tox -e javascript
111
+
112
+ This command runs ``npm install`` to ensure test requirements are up to
113
+ date and then runs ``npm test``.
114
+
48
115
.. _running-unit-tests-settings:
49
116
50
117
Using another ``settings`` module
0 commit comments