Skip to content

Commit 33ad7c8

Browse files
authored
Merge pull request #882 from bluetech/docs-fixes
docs: some fixes/cleanups
2 parents 79b7754 + 4cab057 commit 33ad7c8

File tree

11 files changed

+101
-113
lines changed

11 files changed

+101
-113
lines changed

docs/changelog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ bugs.
656656
The tests for pytest-django itself has been greatly improved, paving the
657657
way for easier additions of new and exciting features in the future!
658658

659-
* Semantic version numbers will now be used for releases, see http://semver.org/.
659+
* Semantic version numbers will now be used for releases, see https://semver.org/.
660660

661661
* Do not allow database access in tests by default. Introduce
662662
``pytest.mark.django_db`` to enable database access.
@@ -720,7 +720,7 @@ v1.1
720720
----
721721

722722
* The initial release of this fork from `Ben Firshman original project
723-
<http://github.com/bfirsh/pytest_django>`__
723+
<https://github.com/bfirsh/pytest_django>`__
724724
* Added documentation
725725
* Uploaded to PyPI for easy installation
726726
* Added the ``transaction_test_case`` decorator for tests that needs real transactions

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040

4141
intersphinx_mapping = {
4242
'python': ('https://docs.python.org/3', None),
43-
'django': ('https://docs.djangoproject.com/en/dev/',
44-
'https://docs.djangoproject.com/en/dev/_objects/'),
45-
'pytest': ('https://docs.pytest.org/en/latest/', None),
43+
'django': ('https://docs.djangoproject.com/en/stable/',
44+
'https://docs.djangoproject.com/en/stable/_objects/'),
45+
'pytest': ('https://docs.pytest.org/en/stable/', None),
4646
}
4747

4848

docs/configuring_django.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ the tests.
99
The environment variable ``DJANGO_SETTINGS_MODULE``
1010
---------------------------------------------------
1111

12-
Running the tests with DJANGO_SETTINGS_MODULE defined will find the
12+
Running the tests with ``DJANGO_SETTINGS_MODULE`` defined will find the
1313
Django settings the same way Django does by default.
1414

1515
Example::

docs/contributing.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,16 @@ double cookie points. Seriously. You rock.
227227

228228
.. _fork: https://github.com/pytest-dev/pytest-django
229229
.. _issue tracker: https://github.com/pytest-dev/pytest-django/issues
230-
.. _Sphinx: http://sphinx.pocoo.org/
231-
.. _PEP8: http://www.python.org/dev/peps/pep-0008/
232-
.. _GitHub : http://www.github.com
233-
.. _GitHub help : http://help.github.com
234-
.. _freenode : http://freenode.net/
230+
.. _Sphinx: https://www.sphinx-doc.org/
231+
.. _PEP8: https://www.python.org/dev/peps/pep-0008/
232+
.. _GitHub : https://www.github.com
233+
.. _GitHub help : https://help.github.com
234+
.. _freenode : https://freenode.net/
235235
.. _@andreaspelme : https://twitter.com/andreaspelme
236-
.. _pull request : http://help.github.com/send-pull-requests/
237-
.. _git : http://git-scm.com/
238-
.. _restructuredText: http://docutils.sourceforge.net/docs/ref/rst/introduction.html
236+
.. _pull request : https://help.github.com/send-pull-requests/
237+
.. _git : https://git-scm.com/
238+
.. _restructuredText: https://docutils.sourceforge.io/docs/ref/rst/introduction.html
239239
.. _django CMS: https://www.django-cms.org/
240240
.. _GitHub Actions: https://github.com/features/actions
241241
.. _pytest-django Actions: https://github.com/pytest-dev/pytest-django/actions
242-
.. _`subprocess section of coverage documentation`: http://nedbatchelder.com/code/coverage/subprocess.html
242+
.. _`subprocess section of coverage documentation`: https://coverage.readthedocs.io/en/latest/subprocess.html

docs/database.rst

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ what code uses the database and catches any mistakes.
1212
Enabling database access in tests
1313
---------------------------------
1414

15-
You can use `pytest marks <https://pytest.org/en/latest/mark.html>`_ to
16-
tell ``pytest-django`` your test needs database access::
15+
You can use :ref:`pytest marks <pytest:mark>` to tell ``pytest-django`` your
16+
test needs database access::
1717

1818
import pytest
1919

@@ -24,10 +24,8 @@ tell ``pytest-django`` your test needs database access::
2424

2525
It is also possible to mark all tests in a class or module at once.
2626
This demonstrates all the ways of marking, even though they overlap.
27-
Just one of these marks would have been sufficient. See the `pytest
28-
documentation
29-
<https://pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules>`_
30-
for detail::
27+
Just one of these marks would have been sufficient. See the :ref:`pytest
28+
documentation <pytest:scoped-marking>` for detail::
3129

3230
import pytest
3331

@@ -45,20 +43,18 @@ By default ``pytest-django`` will set up the Django databases the
4543
first time a test needs them. Once setup the database is cached for
4644
used for all subsequent tests and rolls back transactions to isolate
4745
tests from each other. This is the same way the standard Django
48-
`TestCase
49-
<https://docs.djangoproject.com/en/1.9/topics/testing/tools/#testcase>`_
50-
uses the database. However ``pytest-django`` also caters for
51-
transaction test cases and allows you to keep the test databases
52-
configured across different test runs.
46+
:class:`~django.test.TestCase` uses the database. However
47+
``pytest-django`` also caters for transaction test cases and allows
48+
you to keep the test databases configured across different test runs.
5349

5450

5551
Testing transactions
5652
--------------------
5753

58-
Django itself has the ``TransactionTestCase`` which allows you to test
59-
transactions and will flush the database between tests to isolate
60-
them. The downside of this is that these tests are much slower to
61-
set up due to the required flushing of the database.
54+
Django itself has the :class:`~django.test.TransactionTestCase` which
55+
allows you to test transactions and will flush the database between
56+
tests to isolate them. The downside of this is that these tests are
57+
much slower to set up due to the required flushing of the database.
6258
``pytest-django`` also supports this style of tests, which you can
6359
select using an argument to the ``django_db`` mark::
6460

@@ -83,8 +79,8 @@ directly in ``pytest-django`` please get in touch, we are interested
8379
in eventually supporting this but unsure about simply following
8480
Django's approach.
8581

86-
See `https://github.com/pytest-dev/pytest-django/pull/431` for an idea /
87-
discussion to approach this.
82+
See `pull request 431 <https://github.com/pytest-dev/pytest-django/pull/431>`_
83+
for an idea/discussion to approach this.
8884

8985
``--reuse-db`` - reuse the testing database between test runs
9086
--------------------------------------------------------------
@@ -184,8 +180,9 @@ django_db_modify_db_settings
184180

185181
.. fixture:: django_db_modify_db_settings
186182

187-
This fixture allows modifying `django.conf.settings.DATABASES` just before the
188-
databases are configured.
183+
This fixture allows modifying
184+
`django.conf.settings.DATABASES <https://docs.djangoproject.com/en/stable/ref/settings/#databases>`_
185+
just before the databases are configured.
189186

190187
If you need to customize the location of your test database, this is the
191188
fixture you want to override.
@@ -333,7 +330,7 @@ Put this into ``conftest.py``::
333330
conn.close()
334331

335332

336-
@pytest.yield_fixture(scope='session')
333+
@pytest.fixture(scope='session')
337334
def django_db_setup():
338335
from django.conf import settings
339336

docs/faq.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ for more information.
1616
How can I make sure that all my tests run with a specific locale?
1717
-----------------------------------------------------------------
1818

19-
Create a `pytest fixture <https://pytest.org/en/latest/fixture.html>`_ that is
20-
automatically run before each test case. To run all tests with the english
21-
locale, put the following code in your project's `conftest.py`_ file:
19+
Create a :ref:`pytest fixture <pytest:fixtures>` that is
20+
automatically run before each test case. To run all tests with the English
21+
locale, put the following code in your project's
22+
:ref:`conftest.py <pytest:plugins>` file:
2223

2324
.. code-block:: python
2425
@@ -28,8 +29,6 @@ locale, put the following code in your project's `conftest.py`_ file:
2829
def set_default_language():
2930
activate('en')
3031
31-
.. _conftest.py: http://docs.pytest.org/en/latest/plugins.html
32-
3332
.. _faq-tests-not-being-picked-up:
3433

3534
My tests are not being found. Why?
@@ -55,7 +54,7 @@ When debugging test collection problems, the ``--collectonly`` flag and
5554
``-rs`` (report skipped tests) can be helpful.
5655

5756
.. _related pytest docs:
58-
http://docs.pytest.org/en/latest/example/pythoncollection.html#changing-naming-conventions
57+
https://docs.pytest.org/en/stable/example/pythoncollection.html#changing-naming-conventions
5958

6059
Does pytest-django work with the pytest-xdist plugin?
6160
-----------------------------------------------------
@@ -145,6 +144,6 @@ pytest-django.
145144

146145
Direct help can be found in the #pylib IRC channel on irc.freenode.org.
147146

148-
.. _pytest tag: http://stackoverflow.com/search?q=pytest
147+
.. _pytest tag: https://stackoverflow.com/search?q=pytest
149148
.. _open an issue on the GitHub project:
150149
https://github.com/pytest-dev/pytest-django/issues/

docs/helpers.rst

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,43 @@ All of Django's :py:class:`~django:django.test.TestCase`
1616
Markers
1717
-------
1818

19-
``pytest-django`` registers and uses markers. See the pytest documentation_
20-
on what marks are and for notes on using_ them.
21-
22-
.. _documentation: https://pytest.org/en/latest/mark.html
23-
.. _using: https://pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules
19+
``pytest-django`` registers and uses markers. See the pytest
20+
:ref:`documentation <pytest:mark>` on what marks are and for notes on
21+
:ref:`using <pytest:scoped-marking>` them.
2422

2523

2624
``pytest.mark.django_db`` - request database access
2725
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2826

29-
.. :py:function:: pytest.mark.django_db([transaction=False, reset_sequences=False]):
30-
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-
`django.test.TestCase`_ class.
36-
37-
In order for a test to have access to the database it must either
38-
be marked using the ``django_db`` mark or request one of the ``db``,
39-
``transactional_db`` or ``django_db_reset_sequences`` fixtures. Otherwise the
40-
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-
`django.test.TestCase`_
48-
uses. When ``transaction=True``, the behavior will be the same as
49-
`django.test.TransactionTestCase`_
50-
51-
52-
:type reset_sequences: bool
53-
:param reset_sequences:
54-
The ``reset_sequences`` argument will ask to reset auto increment sequence
55-
values (e.g. primary keys) before running the test. Defaults to
56-
``False``. Must be used together with ``transaction=True`` to have an
57-
effect. Please be aware that not all databases support this feature.
58-
For details see :py:attr:`django.test.TransactionTestCase.reset_sequences`.
27+
.. py:function:: pytest.mark.django_db([transaction=False, reset_sequences=False])
28+
29+
This is used to mark a test function as requiring the database. It
30+
will ensure the database is set up correctly for the test. Each test
31+
will run in its own transaction which will be rolled back at the end
32+
of the test. This behavior is the same as Django's standard
33+
:class:`~django.test.TestCase` class.
34+
35+
In order for a test to have access to the database it must either
36+
be marked using the ``django_db`` mark or request one of the ``db``,
37+
``transactional_db`` or ``django_db_reset_sequences`` fixtures. Otherwise the
38+
test will fail when trying to access the database.
39+
40+
:type transaction: bool
41+
:param transaction:
42+
The ``transaction`` argument will allow the test to use real transactions.
43+
With ``transaction=False`` (the default when not specified), transaction
44+
operations are noops during the test. This is the same behavior that
45+
:class:`django.test.TestCase` uses. When ``transaction=True``, the behavior
46+
will be the same as :class:`django.test.TransactionTestCase`.
47+
48+
49+
:type reset_sequences: bool
50+
:param reset_sequences:
51+
The ``reset_sequences`` argument will ask to reset auto increment sequence
52+
values (e.g. primary keys) before running the test. Defaults to
53+
``False``. Must be used together with ``transaction=True`` to have an
54+
effect. Please be aware that not all databases support this feature.
55+
For details see :py:attr:`django.test.TransactionTestCase.reset_sequences`.
5956

6057
.. note::
6158

@@ -68,13 +65,10 @@ test will fail when trying to access the database.
6865

6966
.. note:: Automatic usage with ``django.test.TestCase``.
7067

71-
Test classes that subclass `django.test.TestCase`_ will have access to
68+
Test classes that subclass :class:`django.test.TestCase` will have access to
7269
the database always to make them compatible with existing Django tests.
73-
Test classes that subclass Python's ``unittest.TestCase`` need to have the
74-
marker applied in order to access the database.
75-
76-
.. _django.test.TestCase: https://docs.djangoproject.com/en/dev/topics/testing/overview/#testcase
77-
.. _django.test.TransactionTestCase: https://docs.djangoproject.com/en/dev/topics/testing/overview/#transactiontestcase
70+
Test classes that subclass Python's :class:`unittest.TestCase` need to have
71+
the marker applied in order to access the database.
7872

7973

8074
``pytest.mark.urls`` - override the urlconf
@@ -119,16 +113,14 @@ Fixtures
119113
--------
120114

121115
pytest-django provides some pytest fixtures to provide dependencies for tests.
122-
More information on fixtures is available in the `pytest documentation
123-
<https://pytest.org/en/latest/fixture.html>`_.
116+
More information on fixtures is available in the :ref:`pytest documentation
117+
<pytest:fixtures>`.
124118

125119

126120
``rf`` - ``RequestFactory``
127121
~~~~~~~~~~~~~~~~~~~~~~~~~~~
128122

129-
An instance of a `django.test.RequestFactory`_
130-
131-
.. _django.test.RequestFactory: https://docs.djangoproject.com/en/dev/topics/testing/advanced/#django.test.RequestFactory
123+
An instance of a :class:`django.test.RequestFactory`.
132124

133125
Example
134126
"""""""
@@ -145,9 +137,7 @@ Example
145137
``client`` - ``django.test.Client``
146138
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147139

148-
An instance of a `django.test.Client`_
149-
150-
.. _django.test.Client: https://docs.djangoproject.com/en/dev/topics/testing/tools/#the-test-client
140+
An instance of a :class:`django.test.Client`.
151141

152142
Example
153143
"""""""
@@ -158,8 +148,9 @@ Example
158148
response = client.get('/')
159149
assert response.content == 'Foobar'
160150

161-
To use `client` as an authenticated standard user, call its `force_login()` or
162-
`login()` method before accessing a URL:
151+
To use `client` as an authenticated standard user, call its
152+
:meth:`force_login() <django.test.Client.force_login>` or
153+
:meth:`login() <django.test.Client.login()>` method before accessing a URL:
163154

164155
::
165156

@@ -178,7 +169,7 @@ To use `client` as an authenticated standard user, call its `force_login()` or
178169
``admin_client`` - ``django.test.Client`` logged in as admin
179170
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180171

181-
An instance of a `django.test.Client`_, logged in as an admin user.
172+
An instance of a :class:`django.test.Client`, logged in as an admin user.
182173

183174
Example
184175
"""""""
@@ -208,7 +199,8 @@ Using the `admin_user` fixture will cause the test to automatically be marked fo
208199
~~~~~~~~~~~~~~~~~~~~~
209200

210201
A shortcut to the User model configured for use by the current Django project (aka the model referenced by
211-
`settings.AUTH_USER_MODEL`). Use this fixture to make pluggable apps testable regardless what User model is configured
202+
`settings.AUTH_USER_MODEL <https://docs.djangoproject.com/en/stable/ref/settings/#auth-user-model>`_).
203+
Use this fixture to make pluggable apps testable regardless what User model is configured
212204
in the containing Django project.
213205

214206
Example
@@ -223,8 +215,9 @@ Example
223215
``django_username_field``
224216
~~~~~~~~~~~~~~~~~~~~~~~~~
225217

226-
This fixture extracts the field name used for the username on the user model, i.e. resolves to the current
227-
``settings.USERNAME_FIELD``. Use this fixture to make pluggable apps testable regardless what the username field
218+
This fixture extracts the field name used for the username on the user model, i.e.
219+
resolves to the user model's :attr:`~django.contrib.auth.models.CustomUser.USERNAME_FIELD`.
220+
Use this fixture to make pluggable apps testable regardless what the username field
228221
is configured to be in the containing Django project.
229222

230223
``db``
@@ -264,7 +257,7 @@ normally use the ``pytest.mark.django_db`` mark with ``transaction=True`` and ``
264257

265258
This fixture runs a live Django server in a background thread. The
266259
server's URL can be retrieved using the ``live_server.url`` attribute
267-
or by requesting it's string value: ``unicode(live_server)``. You can
260+
or by requesting it's string value: ``str(live_server)``. You can
268261
also directly concatenate a string to form a URL: ``live_server +
269262
'/foo``.
270263

@@ -313,8 +306,8 @@ This fixture allows to check for an expected number of DB queries.
313306
If the assertion failed, the executed queries can be shown by using
314307
the verbose command line option.
315308

316-
It wraps `django.test.utils.CaptureQueriesContext` and yields the wrapped
317-
CaptureQueriesContext instance.
309+
It wraps ``django.test.utils.CaptureQueriesContext`` and yields the wrapped
310+
``CaptureQueriesContext`` instance.
318311

319312
Example usage::
320313

0 commit comments

Comments
 (0)