I am having an issue with a custom plugin I am writing to collect py.test results in a rst-formatted file. In the end I would like to include this file into Sphinx docs.
I have written my plugin in the myplugin.py module which is in the current working directory. I then call
py.test -p myplugin ../mytool/test
which ends in an ImportError: No module named myplugin.
I also tried calling it like
py.test -p .myplugin ../mytool/test
like a relative import, but without success.
The Docs give the following information about plugin detection:
Plugin discovery order at tool startup pytest loads plugin modules at tool startup in the following way:
by loading all builtin plugins
by loading all plugins registered through setuptools entry points.
by pre-scanning the command line for the -p name option and loading the specified plugin before actual command line parsing.
by loading all conftest.py files as inferred by the command line invocation:
if no test paths are specified use current dir as a test path if exists, load conftest.py and test*/conftest.py relative to the directory part of the first test path. Note that pytest does not find conftest.py files in deeper nested sub directories at tool startup. It is usually a good idea to keep your conftest.py file in the top level test or project root directory.
- by recursively loading all plugins specified by the pytest_plugins variable in conftest.py files
If the plugin is not importable it is because it is not on sys.path. Try explicitly adding it using the PYTHONPATH variable:
PYTHONPATH=/path/to/dir/of/myplugin py.test -p myplugin ../mytool/test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With