pytest_addoption not working when run from inside a plugin registered inside pytest_configure #9527
Unanswered
lovetheguitar
asked this question in
Q&A
Replies: 1 comment 4 replies
-
pytest_addoption is something that ought to happen waaay before pytest_configure (addoption happens before the config object is even made) as such there is no way to skip it over if you have one general base plugin, why not just have that be a always on plugin to begin with |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all :)
I'm writing a pip installable collection of pytest plugins. So I have multiple entry points to different plugin modules. Each module defines different pytest_ methods and fixtures. All working well so far.
Since I'm trying to abstract different hardware, some of which I might have multiple devices of, I was trying to make my plugin more DRY by defining some BasePlugin class and loading it inside pytest_configure. When my BasePlugin class has a pytest_addoption method those entries are not displayed in help neither do they work when passed on the command line.
e.g. in plugin.py
The flag --myoutside works and is displayed correctly in the help section.
Whereas, --myinside is not displayed in the help section and when being passed on the cli I get "pytest: error: unrecognized arguments: --myoption ...".
I read this https://docs.pytest.org/en/6.2.x/writing_plugins.html#optionally-using-hooks-from-3rd-party-plugins and https://docs.pytest.org/en/6.2.x/reference.html#pytest.hookspec.pytest_addoption, where it states that "This function should be implemented only in plugins or conftest.py files situated at the tests root directory due to how pytest discovers plugins during startup.". So what I'm trying to do is apparently not supported?
I think I could set all the required API calls in my plugin module's globals directly. Is this the way to go or are there more beautiful ways to solve this?
Thanks a lot. :)
Beta Was this translation helpful? Give feedback.
All reactions