Let's say I disabled a pytest plugin in my pytest.ini
file like:
[pytest]
...
addopts=
-p no:myplugin
Now I would like to be able to enable it sometimes with command line arguments, something like:
pytest -p yes:myplugin
Is that possible? Please, if you have better recommendations, I would like to know that too.
pytest loads plugin modules at tool startup in the following way: by scanning the command line for the -p no:name option and blocking that plugin from being loaded (even builtin plugins can be blocked this way). This happens before normal command-line parsing. by loading all builtin plugins.
To ensure all pytest-specific features are available, set the test runner manually: press Ctrl+Alt+S to open the IDE settings and select Tools | Python Integrated Tools, and then select pytest from the Default test runner list.
Running pytest A specific function can be run by providing its name after the :: characters. Markers can be used to group tests. A marked grouped of tests is then run with pytest -m . In addition, we can use expressions to run tests that match names of test functions and classes.
To load the plugin again, use -p pytest_myplugin
. This will work when chained after -p no:myplugin
(either on the command-line, or from pytest.ini's addopts).
What's happening here: when you specify -p no:plugin
, pytest prepends "pytest_" to "plugin". This is because myplugin
is actually imported from pytest_myplugin
. Unfortunately, this convenience isn't mirrored on the loading side, which requires the full module name of the plugin.
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