Skip to content

Commit d26a596

Browse files
committed
Add a warning about usefixtures mark not working in fixtures
Fix #1014
1 parent d7b722e commit d26a596

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

doc/en/fixture.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ a generic feature of the mark mechanism:
943943
Note that the assigned variable *must* be called ``pytestmark``, assigning e.g.
944944
``foomark`` will not activate the fixtures.
945945

946-
Lastly you can put fixtures required by all tests in your project
946+
It is also possible to put fixtures required by all tests in your project
947947
into an ini-file:
948948

949949
.. code-block:: ini
@@ -953,6 +953,22 @@ into an ini-file:
953953
usefixtures = cleandir
954954
955955
956+
.. warning::
957+
958+
Note this mark has no effect in **fixture functions**. For example,
959+
this **will not work as expected**:
960+
961+
.. code-block:: python
962+
963+
@pytest.mark.usefixtures("my_other_fixture")
964+
@pytest.fixture
965+
def my_fixture_that_sadly_wont_use_my_other_fixture():
966+
...
967+
968+
Currently this will not generate any error or warning, but this is intended
969+
to be handled by `#3664 <https://github.com/pytest-dev/pytest/issues/3664>`_.
970+
971+
956972
.. _`autouse`:
957973
.. _`autouse fixtures`:
958974

doc/en/reference.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,14 @@ pytest.mark.usefixtures
170170

171171
Mark a test function as using the given fixture names.
172172

173+
.. warning::
174+
175+
This mark can be used with *test functions* only, having no affect when applied
176+
to a **fixture** function.
177+
173178
.. py:function:: pytest.mark.usefixtures(*names)
174179
175-
:param args: the names of the fixture to use as strings
180+
:param args: the names of the fixture to use, as strings
176181

177182

178183
.. _`pytest.mark.xfail ref`:

0 commit comments

Comments
 (0)