File: usage.rst

package info (click to toggle)
pytest-django 4.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 604 kB
  • sloc: python: 4,006; makefile: 39; sh: 17
file content (80 lines) | stat: -rw-r--r-- 2,639 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
.. _usage:

Usage and invocations
=====================

Basic usage
-----------

When using pytest-django, django-admin.py or manage.py is not used to run
tests. This makes it possible to invoke pytest and other plugins with all its
different options directly.

Running a test suite is done by invoking the pytest command directly::

    pytest

Specific test files or directories can be selected by specifying the test file names directly on
the command line::

    pytest test_something.py a_directory

See the `pytest documentation on Usage and invocations
<https://pytest.org/en/stable/usage.html>`_ for more help on available parameters.

Additional command line options
-------------------------------

``--fail-on-template-vars`` - fail for invalid variables in templates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fail tests that render templates which make use of invalid template variables.

You can switch it on in `pytest.ini`::

    [pytest]
    FAIL_INVALID_TEMPLATE_VARS = True
    
Additional pytest.ini settings
------------------------------

``django_debug_mode`` - change how DEBUG is set
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default tests run with the
`DEBUG <https://docs.djangoproject.com/en/stable/ref/settings/#debug>`_
setting set to ``False``. This is to ensure that the observed output of your
code matches what will be seen in a production setting.

If you want ``DEBUG`` to be set::

    [pytest]
    django_debug_mode = true

You can also use ``django_debug_mode = keep`` to disable the overriding and use
whatever is already set in the Django settings.

Running tests in parallel with pytest-xdist
-------------------------------------------
pytest-django supports running tests on multiple processes to speed up test
suite run time. This can lead to significant speed improvements on multi
core/multi CPU machines.

This requires the pytest-xdist plugin to be available, it can usually be
installed with::

    pip install pytest-xdist

You can then run the tests by running::

    pytest -n <number of processes>

When tests are invoked with xdist, pytest-django will create a separate test
database for each process. Each test database will be given a suffix
(something like "gw0", "gw1") to map to a xdist process. If your database name
is set to "foo", the test database with xdist will be "test_foo_gw0",
"test_foo_gw1" etc.

See the full documentation on `pytest-xdist
<https://github.com/pytest-dev/pytest-xdist/blob/master/README.rst>`_ for more
information. Among other features, pytest-xdist can distribute/coordinate test
execution on remote machines.