From 5c878001eaaf55859c0ae0f0d32b067415592b87 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 2 Jun 2018 20:19:17 -0700 Subject: [PATCH] Manual docs changes so syntax is parseable --- doc/en/bash-completion.rst | 2 +- doc/en/example/simple.rst | 2 ++ doc/en/fixture.rst | 4 +++- doc/en/mark.rst | 5 +++-- doc/en/skipping.rst | 6 +++--- doc/en/writing_plugins.rst | 9 ++++++--- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/doc/en/bash-completion.rst b/doc/en/bash-completion.rst index 58c3d878d..08d978209 100644 --- a/doc/en/bash-completion.rst +++ b/doc/en/bash-completion.rst @@ -14,7 +14,7 @@ Install argcomplete using:: For global activation of all argcomplete enabled python applications run:: - sudo activate-global-python-argcomplete + sudo activate-global-python-argcomplete For permanent (but not global) ``pytest`` activation, use:: diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index 1c18a59fe..3f9991d63 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -283,8 +283,10 @@ and then check for the ``sys._called_from_test`` flag: if hasattr(sys, '_called_from_test'): # called from within a test run + ... else: # called "normally" + ... accordingly in your application. It's also a good idea to use your own application module rather than ``sys`` diff --git a/doc/en/fixture.rst b/doc/en/fixture.rst index f2c5d2e96..a04cfdc46 100644 --- a/doc/en/fixture.rst +++ b/doc/en/fixture.rst @@ -250,9 +250,10 @@ instance, you can simply declare it: .. code-block:: python @pytest.fixture(scope="session") - def smtp(...): + def smtp(): # the returned fixture value will be shared for # all tests needing it + ... 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 @pytest.mark.usefixtures("cleandir", "anotherfixture") + def test(): ... and you may specify fixture usage at the test module level, using a generic feature of the mark mechanism: diff --git a/doc/en/mark.rst b/doc/en/mark.rst index 19c11c58a..58f2bb1df 100644 --- a/doc/en/mark.rst +++ b/doc/en/mark.rst @@ -91,6 +91,7 @@ order doesn't even matter. You probably want to think of your marks as a set her if skipif: for condition in skipif.args: # eval condition + ... # by this: for skipif in item.iter_markers('skipif'): @@ -134,5 +135,5 @@ More details can be found in the `original PR = (3, 0), reason="py2k")), + pytest.param(10, 11, marks=pytest.mark.skipif(sys.version_info >= (3, 0), reason="py2k")), ]) def test_increment(n, expected): assert n + 1 == expected diff --git a/doc/en/writing_plugins.rst b/doc/en/writing_plugins.rst index 2ef760118..419f3fae8 100644 --- a/doc/en/writing_plugins.rst +++ b/doc/en/writing_plugins.rst @@ -150,7 +150,7 @@ it in your setuptools-invocation: setup( name="myproject", - packages = ['myproject'] + packages = ['myproject'], # the following makes a plugin available to pytest entry_points = { @@ -214,9 +214,9 @@ With the following typical ``setup.py`` extract: .. code-block:: python setup( - ... + ..., entry_points={'pytest11': ['foo = pytest_foo.plugin']}, - ... + ..., ) 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): # called after collection is completed # you can modify the ``items`` list + ... Here, ``pytest`` will pass in ``config`` (the pytest config object) 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) def pytest_collection_modifyitems(items): # will execute as early as possible + ... # Plugin 2 @pytest.hookimpl(trylast=True) def pytest_collection_modifyitems(items): # will execute as late as possible + ... # Plugin 3 @pytest.hookimpl(hookwrapper=True)