@@ -960,16 +960,27 @@ def __call__(self, function):
960
960
def fixture (scope = "function" , params = None , autouse = False , ids = None , name = None ):
961
961
"""Decorator to mark a fixture factory function.
962
962
963
- This decorator can be used (with or without parameters) to define a
964
- fixture function. The name of the fixture function can later be
965
- referenced to cause its invocation ahead of running tests: test
966
- modules or classes can use the pytest.mark.usefixtures(fixturename)
967
- marker. Test functions can directly use fixture names as input
963
+ This decorator can be used, with or without parameters, to define a
964
+ fixture function.
965
+
966
+ The name of the fixture function can later be referenced to cause its
967
+ invocation ahead of running tests: test
968
+ modules or classes can use the ``pytest.mark.usefixtures(fixturename)``
969
+ marker.
970
+
971
+ Test functions can directly use fixture names as input
968
972
arguments in which case the fixture instance returned from the fixture
969
973
function will be injected.
970
974
975
+ Fixtures can provide their values to test functions using ``return`` or ``yield``
976
+ statements. When using ``yield`` the code block after the ``yield`` statement is executed
977
+ as teardown code regardless of the test outcome, and must yield exactly once.
978
+
971
979
:arg scope: the scope for which this fixture is shared, one of
972
- "function" (default), "class", "module" or "session".
980
+ ``"function"`` (default), ``"class"``, ``"module"``,
981
+ ``"package"`` or ``"session"``.
982
+
983
+ ``"package"`` is considered **experimental** at this time.
973
984
974
985
:arg params: an optional list of parameters which will cause multiple
975
986
invocations of the fixture function and all of the tests
@@ -990,10 +1001,6 @@ def fixture(scope="function", params=None, autouse=False, ids=None, name=None):
990
1001
to resolve this is to name the decorated function
991
1002
``fixture_<fixturename>`` and then use
992
1003
``@pytest.fixture(name='<fixturename>')``.
993
-
994
- Fixtures can optionally provide their values to test functions using a ``yield`` statement,
995
- instead of ``return``. In this case, the code block after the ``yield`` statement is executed
996
- as teardown code regardless of the test outcome. A fixture function must yield exactly once.
997
1004
"""
998
1005
if callable (scope ) and params is None and autouse is False :
999
1006
# direct decoration
0 commit comments