Skip to content

Commit 09d3874

Browse files
tobiasmcnultytimgraham
authored andcommitted
Fixed #22446 -- Added tox.ini to automate pull request checks.
1 parent 3ea7167 commit 09d3874

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.egg-info
66
*.pot
77
*.py[co]
8+
.tox/
89
__pycache__
910
MANIFEST
1011
dist/

docs/internals/contributing/writing-code/coding-style.txt

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Coding style
44

55
Please follow these coding standards when writing code for inclusion in Django.
66

7+
.. _coding-style-python:
8+
79
Python style
810
============
911

@@ -51,6 +53,8 @@ Python style
5153
(``six.assertRaisesRegex()`` as long as we support Python 2) only if you need
5254
to use regular expression matching.
5355

56+
.. _coding-style-imports:
57+
5458
Imports
5559
=======
5660

docs/internals/contributing/writing-code/javascript.txt

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Closure Compiler library requires `Java`_ 7 or higher.
6060
Please don't forget to run ``compress.py`` and include the ``diff`` of the
6161
minified scripts when submitting patches for Django's JavaScript.
6262

63+
.. _javascript-tests:
64+
6365
JavaScript tests
6466
================
6567

docs/internals/contributing/writing-code/unit-tests.txt

+67
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,73 @@ See :ref:`installing-development-version`.
4545

4646
Having problems? See :ref:`troubleshooting-unit-tests` for some common issues.
4747

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+
48115
.. _running-unit-tests-settings:
49116

50117
Using another ``settings`` module

docs/spelling_wordlist

+1
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ Tomek
841841
toolbar
842842
toolkits
843843
toolset
844+
Tox
844845
trac
845846
tracebacks
846847
transactional

tox.ini

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Tox (http://tox.testrun.org/) is a tool for running tests in multiple
2+
# virtualenvs. This configuration file helps to run the test suite on all
3+
# supported Python versions. To use it, "pip install tox" and then run "tox"
4+
# from this directory.
5+
6+
[tox]
7+
skipsdist = true
8+
envlist =
9+
py3
10+
flake8
11+
docs
12+
isort
13+
14+
# Add environments to use default python2 and python3 installations
15+
[testenv:py2]
16+
basepython = python2
17+
18+
[testenv:py3]
19+
basepython = python3
20+
21+
[testenv]
22+
usedevelop = true
23+
passenv = DJANGO_SETTINGS_MODULE
24+
deps =
25+
py{2,27}: -rtests/requirements/py2.txt
26+
py{3,34,35}: -rtests/requirements/py3.txt
27+
postgres: -rtests/requirements/postgres.txt
28+
mysql: -rtests/requirements/mysql.txt
29+
oracle: -rtests/requirements/oracle.txt
30+
changedir = tests
31+
commands =
32+
{envpython} runtests.py {posargs}
33+
34+
[testenv:flake8]
35+
basepython = python3
36+
usedevelop = false
37+
deps = flake8
38+
changedir = {toxinidir}
39+
commands = flake8 .
40+
41+
[testenv:docs]
42+
# On OS X, as of pyenchant 1.6.6, the docs build only works under Python 2.
43+
basepython = python2
44+
usedevelop = false
45+
whitelist_externals =
46+
make
47+
deps =
48+
Sphinx
49+
pyenchant
50+
sphinxcontrib-spelling
51+
changedir = docs
52+
commands =
53+
make spelling
54+
55+
[testenv:isort]
56+
basepython = python3
57+
usedevelop = false
58+
deps = isort
59+
changedir = {toxinidir}
60+
commands = isort --recursive --check-only --diff django tests scripts
61+
62+
[testenv:javascript]
63+
usedevelop = false
64+
deps =
65+
changedir = {toxinidir}
66+
whitelist_externals = npm
67+
commands =
68+
npm install
69+
npm test

0 commit comments

Comments
 (0)