Skip to content

Commit cf648d9

Browse files
authored
Merge pull request #7474 from nicoddemus/env-vars-docs
2 parents c1c5a2b + 906d849 commit cf648d9

File tree

13 files changed

+42
-61
lines changed

13 files changed

+42
-61
lines changed

changelog/7464.feature.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
Added support for ``NO_COLOR`` and ``FORCE_COLOR`` environment variables to control colored output.
2-
3-
For more information, see `the docs <https://docs.pytest.org/en/stable/reference.html#environment-variables>`__.
1+
Added support for :envvar:`NO_COLOR` and :envvar:`FORCE_COLOR` environment variables to control colored output.

doc/en/assert.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ Assertion introspection details
294294
-------------------------------
295295

296296

297-
298-
299297
Reporting details about a failing assertion is achieved by rewriting assert
300298
statements before they are run. Rewritten assert statements put introspection
301299
information into the assertion failure message. ``pytest`` only rewrites test

doc/en/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ Features
21882188

21892189

21902190
- `#3711 <https://github.com/pytest-dev/pytest/issues/3711>`_: Add the ``--ignore-glob`` parameter to exclude test-modules with Unix shell-style wildcards.
2191-
Add the ``collect_ignore_glob`` for ``conftest.py`` to exclude test-modules with Unix shell-style wildcards.
2191+
Add the :globalvar:`collect_ignore_glob` for ``conftest.py`` to exclude test-modules with Unix shell-style wildcards.
21922192

21932193

21942194
- `#4698 <https://github.com/pytest-dev/pytest/issues/4698>`_: The warning about Python 2.7 and 3.4 not being supported in pytest 5.0 has been removed.

doc/en/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,4 +390,11 @@ def setup(app: "sphinx.application.Sphinx") -> None:
390390
indextemplate="pair: %s; configuration value",
391391
)
392392

393+
app.add_object_type(
394+
"globalvar",
395+
"globalvar",
396+
objname="global variable interpreted by pytest",
397+
indextemplate="pair: %s; global variable interpreted by pytest",
398+
)
399+
393400
configure_logging(app)

doc/en/deprecations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pytest_plugins in non-top-level conftest files
413413

414414
.. versionremoved:: 4.0
415415

416-
Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
416+
Defining :globalvar:`pytest_plugins` is now deprecated in non-top-level conftest.py
417417
files because they will activate referenced plugins *globally*, which is surprising because for all other pytest
418418
features ``conftest.py`` files are only *active* for tests at or below it.
419419

doc/en/example/markers.rst

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -280,37 +280,26 @@ its test methods:
280280
This is equivalent to directly applying the decorator to the
281281
two test functions.
282282

283-
Due to legacy reasons, it is possible to set the ``pytestmark`` attribute on a TestClass like this:
284-
285-
.. code-block:: python
283+
To apply marks at the module level, use the :globalvar:`pytestmark` global variable:
286284

287285
import pytest
286+
pytestmark = pytest.mark.webtest
288287

288+
or multiple markers::
289289

290-
class TestClass:
291-
pytestmark = pytest.mark.webtest
290+
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
292291

293-
or if you need to use multiple markers you can use a list:
292+
293+
Due to legacy reasons, before class decorators were introduced, it is possible to set the
294+
:globalvar:`pytestmark` attribute on a test class like this:
294295

295296
.. code-block:: python
296297
297298
import pytest
298299
299300
300301
class TestClass:
301-
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
302-
303-
You can also set a module level marker::
304-
305-
import pytest
306-
pytestmark = pytest.mark.webtest
307-
308-
or multiple markers::
309-
310-
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
311-
312-
in which case markers will be applied (in left-to-right order) to
313-
all functions and methods defined in the module.
302+
pytestmark = pytest.mark.webtest
314303
315304
.. _`marking individual tests when using parametrize`:
316305

doc/en/example/pythoncollection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ file will be left out:
299299
========================== no tests ran in 0.12s ===========================
300300
301301
It's also possible to ignore files based on Unix shell-style wildcards by adding
302-
patterns to ``collect_ignore_glob``.
302+
patterns to :globalvar:`collect_ignore_glob`.
303303

304304
The following example ``conftest.py`` ignores the file ``setup.py`` and in
305305
addition all files that end with ``*_py2.py`` when executed with a Python 3

doc/en/fixture.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,15 +1213,12 @@ You can specify multiple fixtures like this:
12131213
def test():
12141214
...
12151215
1216-
and you may specify fixture usage at the test module level, using
1217-
a generic feature of the mark mechanism:
1216+
and you may specify fixture usage at the test module level using :globalvar:`pytestmark`:
12181217

12191218
.. code-block:: python
12201219
12211220
pytestmark = pytest.mark.usefixtures("cleandir")
12221221
1223-
Note that the assigned variable *must* be called ``pytestmark``, assigning e.g.
1224-
``foomark`` will not activate the fixtures.
12251222
12261223
It is also possible to put fixtures required by all tests in your project
12271224
into an ini-file:

doc/en/plugins.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ You may also discover more plugins through a `pytest- pypi.org search`_.
7070
Requiring/Loading plugins in a test module or conftest file
7171
-----------------------------------------------------------
7272

73-
You can require plugins in a test module or a conftest file like this:
73+
You can require plugins in a test module or a conftest file using :globalvar:`pytest_plugins`:
7474

7575
.. code-block:: python
7676
@@ -80,6 +80,7 @@ When the test module or conftest plugin is loaded the specified plugins
8080
will be loaded as well.
8181

8282
.. note::
83+
8384
Requiring plugins using a ``pytest_plugins`` variable in non-root
8485
``conftest.py`` files is deprecated. See
8586
:ref:`full explanation <requiring plugins in non-root conftests>`

doc/en/reference.rst

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,14 @@ Result used within :ref:`hook wrappers <hookwrapper>`.
900900
.. automethod:: pluggy.callers._Result.get_result
901901
.. automethod:: pluggy.callers._Result.force_result
902902

903-
Special Variables
904-
-----------------
903+
Global Variables
904+
----------------
905905

906-
pytest treats some global variables in a special manner when defined in a test module.
906+
pytest treats some global variables in a special manner when defined in a test module or
907+
``conftest.py`` files.
907908

908909

909-
collect_ignore
910-
~~~~~~~~~~~~~~
910+
.. globalvar:: collect_ignore
911911

912912
**Tutorial**: :ref:`customizing-test-collection`
913913

@@ -919,8 +919,7 @@ Needs to be ``list[str]``.
919919
collect_ignore = ["setup.py"]
920920
921921
922-
collect_ignore_glob
923-
~~~~~~~~~~~~~~~~~~~
922+
.. globalvar:: collect_ignore_glob
924923

925924
**Tutorial**: :ref:`customizing-test-collection`
926925

@@ -933,8 +932,7 @@ contain glob patterns.
933932
collect_ignore_glob = ["*_ignore.py"]
934933
935934
936-
pytest_plugins
937-
~~~~~~~~~~~~~~
935+
.. globalvar:: pytest_plugins
938936

939937
**Tutorial**: :ref:`available installable plugins`
940938

@@ -950,13 +948,12 @@ Can be either a ``str`` or ``Sequence[str]``.
950948
pytest_plugins = ("myapp.testsupport.tools", "myapp.testsupport.regression")
951949
952950
953-
pytestmark
954-
~~~~~~~~~~
951+
.. globalvar:: pytestmark
955952

956953
**Tutorial**: :ref:`scoped-marking`
957954

958955
Can be declared at the **global** level in *test modules* to apply one or more :ref:`marks <marks ref>` to all
959-
test functions and methods. Can be either a single mark or a list of marks.
956+
test functions and methods. Can be either a single mark or a list of marks (applied in left-to-right order).
960957

961958
.. code-block:: python
962959
@@ -971,12 +968,6 @@ test functions and methods. Can be either a single mark or a list of marks.
971968
972969
pytestmark = [pytest.mark.integration, pytest.mark.slow]
973970
974-
PYTEST_DONT_REWRITE (module docstring)
975-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
976-
977-
The text ``PYTEST_DONT_REWRITE`` can be add to any **module docstring** to disable
978-
:ref:`assertion rewriting <assert introspection>` for that module.
979-
980971
981972
Environment Variables
982973
---------------------

doc/en/skipping.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ You can use the ``skipif`` marker (as any other marker) on classes:
152152
If the condition is ``True``, this marker will produce a skip result for
153153
each of the test methods of that class.
154154

155-
If you want to skip all test functions of a module, you may use
156-
the ``pytestmark`` name on the global level:
155+
If you want to skip all test functions of a module, you may use the
156+
:globalvar:`pytestmark` global:
157157

158158
.. code-block:: python
159159

doc/en/warnings.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Filters applied using a mark take precedence over filters passed on the command
117117
by the ``filterwarnings`` ini option.
118118

119119
You may apply a filter to all tests of a class by using the ``filterwarnings`` mark as a class
120-
decorator or to all tests in a module by setting the ``pytestmark`` variable:
120+
decorator or to all tests in a module by setting the :globalvar:`pytestmark` variable:
121121

122122
.. code-block:: python
123123

doc/en/writing_plugins.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Plugin discovery order at tool startup
5252
your ``conftest.py`` file in the top level test or project root directory.
5353

5454
* by recursively loading all plugins specified by the
55-
``pytest_plugins`` variable in ``conftest.py`` files
55+
:globalvar:`pytest_plugins` variable in ``conftest.py`` files
5656

5757

5858
.. _`pytest/plugin`: http://bitbucket.org/pytest-dev/pytest/src/tip/pytest/plugin/
@@ -227,7 +227,7 @@ import ``helper.py`` normally. The contents of
227227
Requiring/Loading plugins in a test module or conftest file
228228
-----------------------------------------------------------
229229

230-
You can require plugins in a test module or a ``conftest.py`` file like this:
230+
You can require plugins in a test module or a ``conftest.py`` file using :globalvar:`pytest_plugins`:
231231

232232
.. code-block:: python
233233
@@ -241,31 +241,31 @@ application modules:
241241
242242
pytest_plugins = "myapp.testsupport.myplugin"
243243
244-
``pytest_plugins`` variables are processed recursively, so note that in the example above
245-
if ``myapp.testsupport.myplugin`` also declares ``pytest_plugins``, the contents
244+
:globalvar:`pytest_plugins` are processed recursively, so note that in the example above
245+
if ``myapp.testsupport.myplugin`` also declares :globalvar:`pytest_plugins`, the contents
246246
of the variable will also be loaded as plugins, and so on.
247247

248248
.. _`requiring plugins in non-root conftests`:
249249

250250
.. note::
251-
Requiring plugins using a ``pytest_plugins`` variable in non-root
251+
Requiring plugins using :globalvar:`pytest_plugins` variable in non-root
252252
``conftest.py`` files is deprecated.
253253

254254
This is important because ``conftest.py`` files implement per-directory
255255
hook implementations, but once a plugin is imported, it will affect the
256256
entire directory tree. In order to avoid confusion, defining
257-
``pytest_plugins`` in any ``conftest.py`` file which is not located in the
257+
:globalvar:`pytest_plugins` in any ``conftest.py`` file which is not located in the
258258
tests root directory is deprecated, and will raise a warning.
259259

260260
This mechanism makes it easy to share fixtures within applications or even
261261
external applications without the need to create external plugins using
262262
the ``setuptools``'s entry point technique.
263263

264-
Plugins imported by ``pytest_plugins`` will also automatically be marked
264+
Plugins imported by :globalvar:`pytest_plugins` will also automatically be marked
265265
for assertion rewriting (see :func:`pytest.register_assert_rewrite`).
266266
However for this to have any effect the module must not be
267267
imported already; if it was already imported at the time the
268-
``pytest_plugins`` statement is processed, a warning will result and
268+
:globalvar:`pytest_plugins` statement is processed, a warning will result and
269269
assertions inside the plugin will not be rewritten. To fix this you
270270
can either call :func:`pytest.register_assert_rewrite` yourself before
271271
the module is imported, or you can arrange the code to delay the

0 commit comments

Comments
 (0)