Skip to content

Commit 5337357

Browse files
authored
Add setting example using pyproject.toml file. (#1047)
1 parent 90349e5 commit 5337357

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

docs/configuring_django.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ Example contents of pytest.ini::
3838
[pytest]
3939
DJANGO_SETTINGS_MODULE = test.settings
4040

41+
``pyproject.toml`` settings
42+
---------------------------
43+
44+
Example contents of pyproject.toml::
45+
46+
[tool.pytest.ini_options]
47+
DJANGO_SETTINGS_MODULE = "test.settings"
48+
4149
Order of choosing settings
4250
--------------------------
4351

@@ -46,7 +54,7 @@ The order of precedence is, from highest to lowest:
4654
* The command line option ``--ds``
4755
* The environment variable ``DJANGO_SETTINGS_MODULE``
4856
* The ``DJANGO_SETTINGS_MODULE`` option in the configuration file -
49-
``pytest.ini``, or other file that Pytest finds such as ``tox.ini``
57+
``pytest.ini``, or other file that Pytest finds such as ``tox.ini`` or ``pyproject.toml``
5058

5159
If you want to use the highest precedence in the configuration file, you can
5260
use ``addopts = --ds=yourtestsettings``.
@@ -57,7 +65,7 @@ Using django-configurations
5765
There is support for using `django-configurations <https://pypi.python.org/pypi/django-configurations/>`_.
5866

5967
To do so configure the settings class using an environment variable, the
60-
``--dc`` flag, or ``pytest.ini`` option ``DJANGO_CONFIGURATION``.
68+
``--dc`` flag, ``pytest.ini`` option ``DJANGO_CONFIGURATION`` or ``pyproject.toml`` option ``DJANGO_CONFIGURATION``.
6169

6270
Environment Variable::
6371

@@ -73,6 +81,11 @@ INI File Contents::
7381
[pytest]
7482
DJANGO_CONFIGURATION=MySettings
7583

84+
pyproject.toml File Contents::
85+
86+
[tool.pytest.ini_options]
87+
DJANGO_CONFIGURATION = "MySettings"
88+
7689
Using ``django.conf.settings.configure()``
7790
------------------------------------------
7891

docs/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Make sure ``DJANGO_SETTINGS_MODULE`` is defined (see
1919
:ref:`configuring_django_settings`) and make your tests discoverable
2020
(see :ref:`faq-tests-not-being-picked-up`):
2121

22+
Example using pytest.ini or tox.ini
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
2225
.. code-block:: ini
2326
2427
# -- FILE: pytest.ini (or tox.ini)
@@ -27,6 +30,17 @@ Make sure ``DJANGO_SETTINGS_MODULE`` is defined (see
2730
# -- recommended but optional:
2831
python_files = tests.py test_*.py *_tests.py
2932
33+
Example using pyproject.toml
34+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
36+
.. code-block:: toml
37+
38+
# -- Example FILE: pyproject.toml
39+
[tool.pytest.ini_options]
40+
DJANGO_SETTINGS_MODULE = "test.settings"
41+
# -- recommended but optional:
42+
python_files = ["test_*.py", "*_test.py", "testing/python/*.py"]
43+
3044
Run your tests with ``pytest``:
3145

3246
.. code-block:: bash

docs/tutorial.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ contains:
5454
[pytest]
5555
DJANGO_SETTINGS_MODULE = yourproject.settings
5656
57+
Another options for people that use ``pyproject.toml`` is add the following code:
58+
59+
.. code-block:: toml
60+
61+
[tool.pytest.ini_options]
62+
DJANGO_SETTINGS_MODULE = "yourproject.settings"
63+
5764
You can also specify your Django settings by setting the
5865
``DJANGO_SETTINGS_MODULE`` environment variable or specifying the
5966
``--ds=yourproject.settings`` command line flag when running the tests.

0 commit comments

Comments
 (0)