Skip to content

Commit

Permalink
Remove package scope experimental status
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jun 27, 2020
1 parent 7450b6d commit 289197f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelog/7389.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixture scope ``package`` is no longer considered experimental.
34 changes: 14 additions & 20 deletions doc/en/fixture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ and `pytest-datafiles <https://pypi.org/project/pytest-datafiles/>`__.

.. _smtpshared:

Scope: sharing a fixture instance across tests in a class, module or session
----------------------------------------------------------------------------
Scope: sharing fixtures across classes, modules, packages or session
--------------------------------------------------------------------

.. regendoc:wipe
Expand Down Expand Up @@ -356,29 +356,23 @@ instance, you can simply declare it:
# all tests needing it
...
Finally, the ``class`` scope will invoke the fixture once per test *class*.
.. note::

Pytest will only cache one instance of a fixture at a time.
This means that when using a parametrized fixture, pytest may invoke a fixture more than once in the given scope.


``package`` scope (experimental)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fixture scopes
^^^^^^^^^^^^^^

Fixtures are created when first requested by a test, and are destroyed based on their ``scope``:

* ``function``: the default scope, the fixture is destroyed at the end of the test.
* ``class``: the fixture is destroyed during teardown of the last test in the class.
* ``module``: the fixture is destroyed during teardown of the last test in the module.
* ``package``: the fixture is destroyed during teardown of the last test in the package.
* ``session``: the fixture is destroyed at the end of the test session.

In pytest 3.7 the ``package`` scope has been introduced. Package-scoped fixtures
are finalized when the last test of a *package* finishes.

.. warning::
This functionality is considered **experimental** and may be removed in future
versions if hidden corner-cases or serious problems with this functionality
are discovered after it gets more usage in the wild.

Use this new feature sparingly and please make sure to report any issues you find.
.. note::

Pytest only caches one instance of a fixture at a time, which
means that when using a parametrized fixture, pytest may invoke a fixture more than once in
the given scope.

.. _dynamic scope:

Expand Down
3 changes: 1 addition & 2 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,7 @@ def fixture( # noqa: F811
:arg scope: the scope for which this fixture is shared, one of
``"function"`` (default), ``"class"``, ``"module"``,
``"package"`` or ``"session"`` (``"package"`` is considered **experimental**
at this time).
``"package"`` or ``"session"``.
This parameter may also be a callable which receives ``(fixture_name, config)``
as parameters, and must return a ``str`` with one of the values mentioned above.
Expand Down

0 comments on commit 289197f

Please sign in to comment.