~ubuntuone-pqm-team/django/stable

« back to all changes in this revision

Viewing changes to docs/internals/contributing/writing-code/unit-tests.txt

  • Committer: Matias Bordese
  • Date: 2014-08-21 21:22:40 UTC
  • Revision ID: matias.bordese@canonical.com-20140821212240-tij4ms6qzjbdiioz
Tags: 1.5.9
Imported Django 1.5.9 from released tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
The tests cover:
9
9
 
10
 
* Models, the database API and everything else in core Django core (``tests/``),
11
 
* :ref:`contrib-apps` (``django/contrib/<app>/tests`` or ``tests/<app>_...``).
 
10
* Models and the database API (``tests/modeltests``),
 
11
* Everything else in core Django code (``tests/regressiontests``),
 
12
* :ref:`contrib-apps` (``django/contrib/<app>/tests`` or
 
13
  ``tests/regressiontests/<app>_...``).
12
14
 
13
15
We appreciate any and all contributions to the test suite!
14
16
 
15
17
The Django tests all use the testing infrastructure that ships with Django for
16
 
testing applications. See :doc:`/topics/testing/overview` for an explanation of
17
 
how to write new tests.
 
18
testing applications. See :doc:`Testing Django applications
 
19
</topics/testing/overview>` for an explanation of how to write new tests.
18
20
 
19
21
.. _running-unit-tests:
20
22
 
31
33
 
32
34
.. code-block:: bash
33
35
 
34
 
    git clone https://github.com:django/django.git django-repo
 
36
   $ git clone https://github.com:django/django.git django-repo
35
37
    cd django-repo/tests
36
38
    PYTHONPATH=..:$PYTHONPATH python ./runtests.py --settings=test_sqlite
37
39
 
97
99
 
98
100
    ./runtests.py --settings=path.to.settings generic_relations i18n
99
101
 
100
 
How do you find out the names of individual tests? Look in ``tests/`` — each
101
 
directory name there is the name of a test. Contrib app names are also valid
102
 
test names.
 
102
How do you find out the names of individual tests? Look in
 
103
``tests/modeltests`` and ``tests/regressiontests`` — each directory name
 
104
there is the name of a test. Contrib app names are also valid test names.
103
105
 
104
106
If you just want to run a particular class of tests, you can specify a list of
105
107
paths to individual test classes. For example, to run the ``TranslationTests``
107
109
 
108
110
.. code-block:: bash
109
111
 
110
 
    ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests
 
112
    ./runtests.py --settings=path.to.settings i18n.TranslationTests
111
113
 
112
114
Going beyond that, you can specify an individual test method like this:
113
115
 
114
116
.. code-block:: bash
115
117
 
116
 
    ./runtests.py --settings=path.to.settings i18n.tests.TranslationTests.test_lazy_objects
 
118
    ./runtests.py --settings=path.to.settings i18n.TranslationTests.test_lazy_objects
117
119
 
118
120
Running the Selenium tests
119
121
~~~~~~~~~~~~~~~~~~~~~~~~~~
120
122
 
121
123
Some admin tests require Selenium 2, Firefox and Python >= 2.6 to work via a
122
124
real Web browser. To allow those tests to run and not be skipped, you must
123
 
install the selenium_ package (version > 2.13) into your Python path and run
124
 
the tests with the ``--selenium`` option:
 
125
install the selenium_ package (version > 2.13) into your Python path.
 
126
 
 
127
Then, run the tests normally, for example:
125
128
 
126
129
.. code-block:: bash
127
130
 
128
 
    ./runtests.py --settings=test_sqlite --selenium admin_inlines
129
 
 
 
131
    ./runtests.py --settings=test_sqlite admin_inlines
130
132
 
131
133
.. _running-unit-tests-dependencies:
132
134
 
136
138
If you want to run the full suite of tests, you'll need to install a number of
137
139
dependencies:
138
140
 
139
 
*  bcrypt_
140
 
*  docutils_
141
141
*  numpy_
142
 
*  Pillow_
 
142
*  PIL_
 
143
*  py-bcrypt_
143
144
*  PyYAML_
 
145
*  Markdown_
 
146
*  Textile_
 
147
*  Docutils_
144
148
*  pytz_
145
149
*  setuptools_
146
150
*  memcached_, plus a :ref:`supported Python binding <memcached>`
165
169
Each of these dependencies is optional. If you're missing any of them, the
166
170
associated tests will be skipped.
167
171
 
168
 
.. _bcrypt: https://pypi.python.org/pypi/bcrypt
169
 
.. _docutils: https://pypi.python.org/pypi/docutils
170
172
.. _numpy: https://pypi.python.org/pypi/numpy
171
 
.. _Pillow: https://pypi.python.org/pypi/Pillow/
 
173
.. _PIL: https://pypi.python.org/pypi/PIL
 
174
.. _py-bcrypt: https://pypi.python.org/pypi/py-bcrypt/
172
175
.. _PyYAML: http://pyyaml.org/wiki/PyYAML
 
176
.. _Markdown: http://pypi.python.org/pypi/Markdown/1.7
 
177
.. _Textile: http://pypi.python.org/pypi/textile
 
178
.. _docutils: http://pypi.python.org/pypi/docutils/0.4
173
179
.. _pytz: https://pypi.python.org/pypi/pytz/
174
 
.. _setuptools: https://pypi.python.org/pypi/setuptools/
 
180
.. _setuptools: http://pypi.python.org/pypi/setuptools/
175
181
.. _memcached: http://memcached.org/
176
182
.. _gettext: http://www.gnu.org/software/gettext/manual/gettext.html
177
 
.. _selenium: https://pypi.python.org/pypi/selenium
178
 
.. _pip requirements files: http://www.pip-installer.org/en/latest/cookbook.html#requirements-files
 
183
.. _selenium: http://pypi.python.org/pypi/selenium
 
184
.. _pip requirements files: http://www.pip-installer.org/en/latest/requirements.html
179
185
 
180
186
Code coverage
181
187
~~~~~~~~~~~~~
209
215
For the tests to be found, a ``models.py`` file must exist, even if it's empty.
210
216
If you have URLs that need to be mapped, put them in ``tests/urls.py``.
211
217
 
212
 
To run tests for just one contrib app (e.g. ``auth``), use the same
 
218
To run tests for just one contrib app (e.g. ``markup``), use the same
213
219
method as above::
214
220
 
215
 
    ./runtests.py --settings=settings django.contrib.auth
 
221
    ./runtests.py --settings=settings markup