-
so as the title says it, I want to use a conftest.py outside from the tests folder where I customize the html report. Unfortunatly the When the conftest.py is inside the tests folder then: @pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
global ADD_LOGOS
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
# getting the docstrings from functions
report = outcome.get_result()
report.description = str(item.function.__doc__)
test_fn = item.obj
docstring = getattr(test_fn, '__doc__')
if docstring:
report.nodeid = docstring Have I done something wrong with the decorator? Thanks for any hints |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Any idea here @RonnyPfannschmidt ? I'd say this is a question for pytest, and not this plugin. Note that It doesn't seem used in the provided snippet. |
Beta Was this translation helpful? Give feedback.
-
the general suggestion for when you want to use plugin code outside of a conftet is to make it a normal python module that a conftest could load as plugin |
Beta Was this translation helpful? Give feedback.
-
if anybody is ever interested in knowing the solution, I reused code from this post: def pytest_configure(config):
config._foo = FooBar()
config.pluginmanager.register(config._foo)
def pytest_unconfigure(config):
foo = getattr(config, '_foo', None)
if foo:
del config._foo
config.pluginmanager.unregister(foo)
class FooBar(object):
# add docstrings from test cases to reports
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(self, item, call):
outcome = yield
# getting the docstrings from functions, run at test set up
report = outcome.get_result()
report.description = str(item.function.__doc__)
test_fn = item.obj
docstring = getattr(test_fn, '__doc__')
if docstring:
report.nodeid = docstring |
Beta Was this translation helpful? Give feedback.
if anybody is ever interested in knowing the solution, I reused code from this post:
https://github.com/pytest-dev/pytest-xdist/issues/79?ref=pythonrepo.com
and now pytest_runtest_makereport on my conftest.py gets called, the code looks like this: