On Mon, Jul 1, 2019 at 9:21 AM Chris Dent <cd...@anticdent.org> wrote:
> On Mon, 1 Jul 2019, Bruno Oliveira wrote: > > On Mon, Jul 1, 2019 at 8:17 AM Chris Dent <cd...@anticdent.org> wrote: > > Is Gabbi + pytest a plugin? If so, you could store the config object > during > > pytest_configure to reuse later: > > Thanks for the quick response. > > It's sort of a plugin. It uses plugin mechanisms to manage the > collection process and manage fixtures that are scoped over a > sequence of tests (instead of just one test). > > The issue is that in the deployed tests already using gabbi, > there is no conftest.py nor python test file that is fully > "pytest aware" from which to load the plugin. Instead the test > file calls a function which itself loads pytest and then loads > the plugin: > > import pytest > pluginmanager = pytest.config.pluginmanager > pluginmanager.import_plugin('gabbi.pytester') > Hmmm strange, because for "pytest.config" to be available, it means the user is running the "pytest" command. You can see here how pytest used to do it: https://github.com/pytest-dev/pytest/blob/d3549df5b94137453b832345a9b8074f518731b0/src/_pytest/main.py#L191-L192 (It is inserting a wrapper object to issue a warning, but other than that the mechanism is there) So in theory your plugin is running under pytest, otherwise `pytest.config` would raise an AttributeError. Messing about just now I see that I've got access to a metafunc and > it has a `config` so this seems to be working: > > if metafunc: > pluginmanager = metafunc.config.pluginmanager > else: > import pytest > pluginmanager = pytest.config.pluginmanager > > (There are older calling scenarios where metafunc will be None.) > > Is this a suitable workaround or am I opening myself up for future > trouble by doing this? > We don't have any plans to deprecate `metafunc.config`, as doing so would break *tons* of code, and is really part of the API and no great downsides (as opposed to the pytest.config which was a nasty global). If you can't make the "pytest_configure" suggestion work, this seems OK to me. Cheers, Bruno
_______________________________________________ pytest-dev mailing list pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev