test_ok2/py/doc/test-plugins.txt

57 lines
1.9 KiB
Plaintext

Many of py.test's features are implemented as a plugin.
Available plugins
-----------------------
py.test has a number of default plugins. You can see which
ones by specifying ``--trace=config``.
* adding reporting facilities, examples:
pytest_terminal: default reporter for writing info to terminals
pytest_resultlog: log test results in machine-readable form to a file
pytest_eventlog: log all internal pytest events to a file
* marking and reporting test specially
pytest_xfail: "expected to fail" test marker
* funcargs for advanced
pytest_tmpdir: provide temporary directories to test functions
pytest_plugintester: generic apichecks, support for functional plugin tests
pytest_pytester: support for testing py.test runs
* extending test execution, e.g.
pytest_apigen: tracing values of function/method calls when running tests
Loading plugins and specifying dependencies
---------------------------------------------------------
py.test loads and configures plugins at tool startup:
* by reading the ``PYTEST_PLUGINS`` environment variable
and importing the comma-separated list of plugin names.
* by loading all plugins specified via one or more ``-p name``
command line options.
* by loading all plugins specified via a ``pytest_plugins``
variable in ``conftest.py`` files or test modules.
example: ensure a plugin is loaded
++++++++++++++++++++++++++++++++++++
If you create a ``conftest.py`` file with the following content::
pytest_plugins = "pytest_myextension",
then all tests in that directory and below it will run with
an instantiated "pytest_myextension". Here is how instantiation
takes place:
* the module ``pytest_extension`` will be imported and
and its contained `ExtensionPlugin`` class will
be instantiated. A plugin module may specify its
dependencies via another ``pytest_plugins`` definition.