Manual docs changes so syntax is parseable
This commit is contained in:
parent
4dc5f7897d
commit
5c878001ea
|
@ -283,8 +283,10 @@ and then check for the ``sys._called_from_test`` flag:
|
||||||
|
|
||||||
if hasattr(sys, '_called_from_test'):
|
if hasattr(sys, '_called_from_test'):
|
||||||
# called from within a test run
|
# called from within a test run
|
||||||
|
...
|
||||||
else:
|
else:
|
||||||
# called "normally"
|
# called "normally"
|
||||||
|
...
|
||||||
|
|
||||||
accordingly in your application. It's also a good idea
|
accordingly in your application. It's also a good idea
|
||||||
to use your own application module rather than ``sys``
|
to use your own application module rather than ``sys``
|
||||||
|
|
|
@ -250,9 +250,10 @@ instance, you can simply declare it:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def smtp(...):
|
def smtp():
|
||||||
# the returned fixture value will be shared for
|
# the returned fixture value will be shared for
|
||||||
# all tests needing it
|
# all tests needing it
|
||||||
|
...
|
||||||
|
|
||||||
Finally, the ``class`` scope will invoke the fixture once per test *class*.
|
Finally, the ``class`` scope will invoke the fixture once per test *class*.
|
||||||
|
|
||||||
|
@ -867,6 +868,7 @@ You can specify multiple fixtures like this:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@pytest.mark.usefixtures("cleandir", "anotherfixture")
|
@pytest.mark.usefixtures("cleandir", "anotherfixture")
|
||||||
|
def test(): ...
|
||||||
|
|
||||||
and you may specify fixture usage at the test module level, using
|
and you may specify fixture usage at the test module level, using
|
||||||
a generic feature of the mark mechanism:
|
a generic feature of the mark mechanism:
|
||||||
|
|
|
@ -91,6 +91,7 @@ order doesn't even matter. You probably want to think of your marks as a set her
|
||||||
if skipif:
|
if skipif:
|
||||||
for condition in skipif.args:
|
for condition in skipif.args:
|
||||||
# eval condition
|
# eval condition
|
||||||
|
...
|
||||||
|
|
||||||
# by this:
|
# by this:
|
||||||
for skipif in item.iter_markers('skipif'):
|
for skipif in item.iter_markers('skipif'):
|
||||||
|
|
|
@ -150,7 +150,7 @@ it in your setuptools-invocation:
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="myproject",
|
name="myproject",
|
||||||
packages = ['myproject']
|
packages = ['myproject'],
|
||||||
|
|
||||||
# the following makes a plugin available to pytest
|
# the following makes a plugin available to pytest
|
||||||
entry_points = {
|
entry_points = {
|
||||||
|
@ -214,9 +214,9 @@ With the following typical ``setup.py`` extract:
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
...
|
...,
|
||||||
entry_points={'pytest11': ['foo = pytest_foo.plugin']},
|
entry_points={'pytest11': ['foo = pytest_foo.plugin']},
|
||||||
...
|
...,
|
||||||
)
|
)
|
||||||
|
|
||||||
In this case only ``pytest_foo/plugin.py`` will be rewritten. If the
|
In this case only ``pytest_foo/plugin.py`` will be rewritten. If the
|
||||||
|
@ -425,6 +425,7 @@ Let's look at a possible implementation:
|
||||||
def pytest_collection_modifyitems(config, items):
|
def pytest_collection_modifyitems(config, items):
|
||||||
# called after collection is completed
|
# called after collection is completed
|
||||||
# you can modify the ``items`` list
|
# you can modify the ``items`` list
|
||||||
|
...
|
||||||
|
|
||||||
Here, ``pytest`` will pass in ``config`` (the pytest config object)
|
Here, ``pytest`` will pass in ``config`` (the pytest config object)
|
||||||
and ``items`` (the list of collected test items) but will not pass
|
and ``items`` (the list of collected test items) but will not pass
|
||||||
|
@ -511,11 +512,13 @@ after others, i.e. the position in the ``N``-sized list of functions:
|
||||||
@pytest.hookimpl(tryfirst=True)
|
@pytest.hookimpl(tryfirst=True)
|
||||||
def pytest_collection_modifyitems(items):
|
def pytest_collection_modifyitems(items):
|
||||||
# will execute as early as possible
|
# will execute as early as possible
|
||||||
|
...
|
||||||
|
|
||||||
# Plugin 2
|
# Plugin 2
|
||||||
@pytest.hookimpl(trylast=True)
|
@pytest.hookimpl(trylast=True)
|
||||||
def pytest_collection_modifyitems(items):
|
def pytest_collection_modifyitems(items):
|
||||||
# will execute as late as possible
|
# will execute as late as possible
|
||||||
|
...
|
||||||
|
|
||||||
# Plugin 3
|
# Plugin 3
|
||||||
@pytest.hookimpl(hookwrapper=True)
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
|
Loading…
Reference in New Issue