You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -14,15 +14,112 @@ configurations files by using the general help option:
14
14
This will display command line and configuration file settings
15
15
which were registered by installed plugins.
16
16
17
+
.. _`config file formats`:
18
+
19
+
Configuration file formats
20
+
--------------------------
21
+
22
+
Many :ref:`pytest settings <ini options ref>` can be set in a *configuration file*, which
23
+
by convention resides on the root of your repository or in your
24
+
tests folder.
25
+
26
+
A quick example of the configuration files supported by pytest:
27
+
28
+
pytest.ini
29
+
~~~~~~~~~~
30
+
31
+
``pytest.ini`` files take precedence over other files, even when empty.
32
+
33
+
.. code-block:: ini
34
+
35
+
# pytest.ini
36
+
[pytest]
37
+
minversion = 6.0
38
+
addopts = -ra -q
39
+
testpaths =
40
+
tests
41
+
integration
42
+
43
+
44
+
pyproject.toml
45
+
~~~~~~~~~~~~~~
46
+
47
+
.. versionadded:: 6.0
48
+
49
+
``pyproject.toml`` are considered for configuration when they contain a ``tool.pytest.ini_options`` table.
50
+
51
+
.. code-block:: toml
52
+
53
+
# pyproject.toml
54
+
[tool.pytest.ini_options]
55
+
minversion = "6.0"
56
+
addopts = "-ra -q"
57
+
testpaths = [
58
+
"tests",
59
+
"integration",
60
+
]
61
+
62
+
.. note::
63
+
64
+
One might wonder why ``[tool.pytest.ini_options]`` instead of ``[tool.pytest]`` as is the
65
+
case with other tools.
66
+
67
+
The reason is that the pytest team intends to fully utilize the rich TOML data format
68
+
for configuration in the future, reserving the ``[tool.pytest]`` table for that.
69
+
The ``ini_options`` table is being used, for now, as a bridge between the existing
70
+
``.ini`` configuration system and the future configuration format.
71
+
72
+
tox.ini
73
+
~~~~~~~
74
+
75
+
``tox.ini`` files are the configuration files of the `tox <https://tox.readthedocs.io>`__ project,
76
+
and can also be used to hold pytest configuration if they have a ``[pytest]`` section.
77
+
78
+
.. code-block:: ini
79
+
80
+
# tox.ini
81
+
[pytest]
82
+
minversion = 6.0
83
+
addopts = -ra -q
84
+
testpaths =
85
+
tests
86
+
integration
87
+
88
+
89
+
setup.cfg
90
+
~~~~~~~~~
91
+
92
+
``setup.cfg`` files are general purpose configuration files, used originally by `distutils <https://docs.python.org/3/distutils/configfile.html>`__, and can also be used to hold pytest configuration
93
+
if they have a ``[tool:pytest]`` section.
94
+
95
+
.. code-block:: ini
96
+
97
+
# setup.cfg
98
+
[tool:pytest]
99
+
minversion = 6.0
100
+
addopts = -ra -q
101
+
testpaths =
102
+
tests
103
+
integration
104
+
105
+
.. warning::
106
+
107
+
Usage of ``setup.cfg`` is not recommended unless for very simple use cases. ``.cfg``
108
+
files use a different parser than ``pytest.ini`` and ``tox.ini`` which might cause hard to track
109
+
down problems.
110
+
When possible, it is recommended to use the latter files, or ``pyproject.toml``, to hold your
111
+
pytest configuration.
112
+
113
+
17
114
.. _rootdir:
18
-
.. _inifiles:
115
+
.. _configfiles:
19
116
20
-
Initialization: determining rootdir and inifile
21
-
-----------------------------------------------
117
+
Initialization: determining rootdir and configfile
0 commit comments