Skip to content

Commit 73a7ea3

Browse files
authored
..
1 parent 7bf7264 commit 73a7ea3

4 files changed

Lines changed: 92 additions & 91 deletions

File tree

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ indent_size = 2
2121

2222
[*.json]
2323
indent_size = 2
24+
insert_final_newline = false
2425

2526
[*.rst]
2627
indent_size = 4

docs/helpers.rst

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -28,82 +28,82 @@ dynamically in a hook or fixture.
2828

2929
.. decorator:: pytest.mark.django_db([transaction=False, reset_sequences=False, databases=None, serialized_rollback=False, available_apps=None])
3030

31-
This is used to mark a test function as requiring the database. It
32-
will ensure the database is set up correctly for the test. Each test
33-
will run in its own transaction which will be rolled back at the end
34-
of the test. This behavior is the same as Django's standard
35-
:class:`~django.test.TestCase` class.
36-
37-
In order for a test to have access to the database it must either be marked
38-
using the :func:`~pytest.mark.django_db` mark or request one of the :fixture:`db`,
39-
:fixture:`transactional_db` or :fixture:`django_db_reset_sequences` fixtures.
40-
Otherwise the test will fail when trying to access the database.
41-
42-
:type transaction: bool
43-
:param transaction:
44-
The ``transaction`` argument will allow the test to use real transactions.
45-
With ``transaction=False`` (the default when not specified), transaction
46-
operations are noops during the test. This is the same behavior that
47-
:class:`django.test.TestCase` uses. When ``transaction=True``, the behavior
48-
will be the same as :class:`django.test.TransactionTestCase`.
49-
50-
51-
:type reset_sequences: bool
52-
:param reset_sequences:
53-
The ``reset_sequences`` argument will ask to reset auto increment sequence
54-
values (e.g. primary keys) before running the test. Defaults to
55-
``False``. Must be used together with ``transaction=True`` to have an
56-
effect. Please be aware that not all databases support this feature.
57-
For details see :attr:`django.test.TransactionTestCase.reset_sequences`.
58-
59-
60-
:type databases: Iterable[str] | str | None
61-
:param databases:
62-
63-
The ``databases`` argument defines which databases in a multi-database
64-
configuration will be set up and may be used by the test. Defaults to
65-
only the ``default`` database. The special value ``"__all__"`` may be used
66-
to specify all configured databases.
67-
For details see :attr:`django.test.TransactionTestCase.databases` and
68-
:attr:`django.test.TestCase.databases`.
69-
70-
:type serialized_rollback: bool
71-
:param serialized_rollback:
72-
The ``serialized_rollback`` argument enables :ref:`rollback emulation
73-
<test-case-serialized-rollback>`. After a transactional test (or any test
74-
using a database backend which doesn't support transactions) runs, the
75-
database is flushed, destroying data created in data migrations. Setting
76-
``serialized_rollback=True`` tells Django to serialize the database content
77-
during setup, and restore it during teardown.
78-
79-
Note that this will slow down that test suite by approximately 3x.
80-
81-
:type available_apps: Iterable[str] | None
82-
:param available_apps:
83-
.. caution::
84-
85-
This argument is **experimental** and is subject to change without
86-
deprecation.
87-
88-
The ``available_apps`` argument defines a subset of apps that are enabled
89-
for a specific set of tests. Setting ``available_apps`` configures models
90-
for which types/permissions will be created before each test, and which
91-
model tables will be emptied after each test (this truncation may cascade
92-
to unavailable apps models).
93-
94-
For details see :attr:`django.test.TransactionTestCase.available_apps`
31+
This is used to mark a test function as requiring the database. It
32+
will ensure the database is set up correctly for the test. Each test
33+
will run in its own transaction which will be rolled back at the end
34+
of the test. This behavior is the same as Django's standard
35+
:class:`~django.test.TestCase` class.
36+
37+
In order for a test to have access to the database it must either be marked
38+
using the :func:`~pytest.mark.django_db` mark or request one of the :fixture:`db`,
39+
:fixture:`transactional_db` or :fixture:`django_db_reset_sequences` fixtures.
40+
Otherwise the test will fail when trying to access the database.
41+
42+
:type transaction: bool
43+
:param transaction:
44+
The ``transaction`` argument will allow the test to use real transactions.
45+
With ``transaction=False`` (the default when not specified), transaction
46+
operations are noops during the test. This is the same behavior that
47+
:class:`django.test.TestCase` uses. When ``transaction=True``, the behavior
48+
will be the same as :class:`django.test.TransactionTestCase`.
49+
50+
51+
:type reset_sequences: bool
52+
:param reset_sequences:
53+
The ``reset_sequences`` argument will ask to reset auto increment sequence
54+
values (e.g. primary keys) before running the test. Defaults to
55+
``False``. Must be used together with ``transaction=True`` to have an
56+
effect. Please be aware that not all databases support this feature.
57+
For details see :attr:`django.test.TransactionTestCase.reset_sequences`.
58+
59+
60+
:type databases: Iterable[str] | str | None
61+
:param databases:
62+
63+
The ``databases`` argument defines which databases in a multi-database
64+
configuration will be set up and may be used by the test. Defaults to
65+
only the ``default`` database. The special value ``"__all__"`` may be used
66+
to specify all configured databases.
67+
For details see :attr:`django.test.TransactionTestCase.databases` and
68+
:attr:`django.test.TestCase.databases`.
69+
70+
:type serialized_rollback: bool
71+
:param serialized_rollback:
72+
The ``serialized_rollback`` argument enables :ref:`rollback emulation
73+
<test-case-serialized-rollback>`. After a transactional test (or any test
74+
using a database backend which doesn't support transactions) runs, the
75+
database is flushed, destroying data created in data migrations. Setting
76+
``serialized_rollback=True`` tells Django to serialize the database content
77+
during setup, and restore it during teardown.
78+
79+
Note that this will slow down that test suite by approximately 3x.
80+
81+
:type available_apps: Iterable[str] | None
82+
:param available_apps:
83+
.. caution::
84+
85+
This argument is **experimental** and is subject to change without
86+
deprecation.
87+
88+
The ``available_apps`` argument defines a subset of apps that are enabled
89+
for a specific set of tests. Setting ``available_apps`` configures models
90+
for which types/permissions will be created before each test, and which
91+
model tables will be emptied after each test (this truncation may cascade
92+
to unavailable apps models).
93+
94+
For details see :attr:`django.test.TransactionTestCase.available_apps`
9595

9696

9797
.. note::
9898

99-
If you want access to the Django database inside a *fixture*, this marker may
100-
or may not help even if the function requesting your fixture has this marker
101-
applied, depending on pytest's fixture execution order. To access the database
102-
in a fixture, it is recommended that the fixture explicitly request one of the
103-
:fixture:`db`, :fixture:`transactional_db`,
104-
:fixture:`django_db_reset_sequences` or
105-
:fixture:`django_db_serialized_rollback` fixtures. See below for a description
106-
of them.
99+
If you want access to the Django database inside a *fixture*, this marker may
100+
or may not help even if the function requesting your fixture has this marker
101+
applied, depending on pytest's fixture execution order. To access the database
102+
in a fixture, it is recommended that the fixture explicitly request one of the
103+
:fixture:`db`, :fixture:`transactional_db`,
104+
:fixture:`django_db_reset_sequences` or
105+
:fixture:`django_db_serialized_rollback` fixtures. See below for a description
106+
of them.
107107

108108
.. note:: Automatic usage with ``django.test.TestCase``.
109109

@@ -118,36 +118,36 @@ dynamically in a hook or fixture.
118118

119119
.. decorator:: pytest.mark.urls(urls)
120120

121-
Specify a different ``settings.ROOT_URLCONF`` module for the marked tests.
121+
Specify a different ``settings.ROOT_URLCONF`` module for the marked tests.
122122

123-
:type urls: str
124-
:param urls:
125-
The urlconf module to use for the test, e.g. ``myapp.test_urls``. This is
126-
similar to Django's ``TestCase.urls`` attribute.
123+
:type urls: str
124+
:param urls:
125+
The urlconf module to use for the test, e.g. ``myapp.test_urls``. This is
126+
similar to Django's ``TestCase.urls`` attribute.
127127

128-
Example usage::
128+
Example usage::
129129

130-
@pytest.mark.urls('myapp.test_urls')
131-
def test_something(client):
132-
assert b'Success!' in client.get('/some_url_defined_in_test_urls/').content
130+
@pytest.mark.urls('myapp.test_urls')
131+
def test_something(client):
132+
assert b'Success!' in client.get('/some_url_defined_in_test_urls/').content
133133

134134

135135
``pytest.mark.ignore_template_errors`` - ignore invalid template variables
136136
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137137

138138
.. decorator:: pytest.mark.ignore_template_errors
139139

140-
Ignore errors when using the ``--fail-on-template-vars`` option, i.e.
141-
do not cause tests to fail if your templates contain invalid variables.
140+
Ignore errors when using the ``--fail-on-template-vars`` option, i.e.
141+
do not cause tests to fail if your templates contain invalid variables.
142142

143-
This marker sets the ``string_if_invalid`` template option.
144-
See :ref:`django:invalid-template-variables`.
143+
This marker sets the ``string_if_invalid`` template option.
144+
See :ref:`django:invalid-template-variables`.
145145

146-
Example usage::
146+
Example usage::
147147

148-
@pytest.mark.ignore_template_errors
149-
def test_something(client):
150-
client('some-url-with-invalid-template-vars')
148+
@pytest.mark.ignore_template_errors
149+
def test_something(client):
150+
client('some-url-with-invalid-template-vars')
151151

152152

153153
Fixtures

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can switch it on in `pytest.ini`::
3333

3434
[pytest]
3535
FAIL_INVALID_TEMPLATE_VARS = True
36-
36+
3737
Additional pytest.ini settings
3838
------------------------------
3939

tests/test_fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def test_set(settings):
419419
420420
def test_set_non_existent(settings):
421421
settings.FOOBAR = 'abc123'
422-
"""
422+
"""
423423
)
424424

425425
result = django_pytester.runpytest_subprocess("--tb=short", "-v", "-s")

0 commit comments

Comments
 (0)