diff options
author | Christoph Buchner <bilderbuchi@phononoia.at> | 2017-10-17 23:42:32 +0200 |
---|---|---|
committer | Christoph Buchner <bilderbuchi@phononoia.at> | 2017-10-17 23:42:32 +0200 |
commit | baadd569e8e1be13fc0d7b0c55273520f5367463 (patch) | |
tree | e01a47afa9f33775d7fd25ff066003f2e5d1e2b7 /doc | |
parent | ae4e596b31fd0ecf8f57b94ba8b5380baba2d4a3 (diff) | |
download | pytest-baadd569e8e1be13fc0d7b0c55273520f5367463.tar.gz |
Clarify the documentation of fixture scopes. Closes #538.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/en/fixture.rst | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/doc/en/fixture.rst b/doc/en/fixture.rst index db7ef0ca2..73f38d726 100644 --- a/doc/en/fixture.rst +++ b/doc/en/fixture.rst @@ -27,7 +27,7 @@ functions: * fixture management scales from simple unit to complex functional testing, allowing to parametrize fixtures and tests according to configuration and component options, or to re-use fixtures - across class, module or whole test session scopes. + across function, class, module or whole test session scopes. In addition, pytest continues to support :ref:`xunitsetup`. You can mix both styles, moving incrementally from classic to new style, as you @@ -129,8 +129,8 @@ functions take the role of the *injector* and test functions are the .. _smtpshared: -Sharing a fixture across tests in a module (or class/session) ------------------------------------------------------------------ +Scope: Sharing a fixture across tests in a class, module or session +------------------------------------------------------------------- .. regendoc:wipe @@ -139,10 +139,12 @@ usually time-expensive to create. Extending the previous example, we can add a ``scope='module'`` parameter to the :py:func:`@pytest.fixture <_pytest.python.fixture>` invocation to cause the decorated ``smtp`` fixture function to only be invoked once -per test module. Multiple test functions in a test module will thus -each receive the same ``smtp`` fixture instance. The next example puts -the fixture function into a separate ``conftest.py`` file so -that tests from multiple test modules in the directory can +per test *module* (the default is to invoke once per test *function*). +Multiple test functions in a test module will thus +each receive the same ``smtp`` fixture instance, thus saving time. + +The next example puts the fixture function into a separate ``conftest.py`` file +so that tests from multiple test modules in the directory can access the fixture function:: # content of conftest.py @@ -223,6 +225,8 @@ instance, you can simply declare it: # the returned fixture value will be shared for # all tests needing it +Finally, the ``class`` scope will invoke the fixture once per test *class*. + .. _`finalization`: Fixture finalization / executing teardown code |