Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest: how to explicitly enable a plugin in command line

Tags:

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.

like image 871
eLRuLL Avatar asked Feb 17 '17 20:02

eLRuLL


People also ask

How does pytest load plugins?

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.

How do I enable pytest?

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.

How do I run a specific pytest function?

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.


1 Answers

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.

like image 94
theY4Kman Avatar answered Oct 14 '22 03:10

theY4Kman