Closed toolsh closed 4 years ago
@toolsh,
A common way to workaround this is by installing a "subplugin":
# conftest.py
def pytest_configure(config):
config.pluginmanager.register(MyPlugin())
class MyPlugin:
def pytest_configure(self, config):
self.config = config
def pytest_runtest_logstart(self, nodeid, location):
... # access self.config
def pytest_runtest_logfinish(self, nodeid, location):
... # access self.config
(Similar approach to access session
).
Adding new parameters to hooks is usually trivial, but unfortunately adding the config
parameter to those two hooks in particular are a bit problematic because we need to also update pytest-xdist
, which calls the hooks directly.
Closing this as the question seems to have been answered 😄
pip list
from the virtual environment you are usingBackground
request.config
(via therequest fixture
) or if you are a plugin author use thepytest_configure(config)
hook. Many hooks can also access theconfig
object indirectly, throughsession.config
oritem.config
for example.Issue
config
object in hookpytest_runtest_logstart(nodeid, location)
andpytest_runtest_logfinish(nodeid, location)
? The two hooks has norequest
oritem
orsession
input parameter.pytest_runtest_logstart
andpytest_runtest_logfinish
are called bypytest_runtest_protocol
only, a hacking way to acessconfig
object would be moving codes intopytest_runtest_protocol
from the two hooks. This is abuse of hooks because it makes the two hooks useless. Is there a way that to accessconfig
object directly in the two hooks?