Have I done something wrong with the decorator? Thanks for any hints
","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"if anybody is ever interested in knowing the solution, I reused code from this post:
\nhttps://github.com/pytest-dev/pytest-xdist/issues/79?ref=pythonrepo.com
\nand now pytest_runtest_makereport on my conftest.py gets called, the code looks like this:
def pytest_configure(config):\n config._foo = FooBar()\n config.pluginmanager.register(config._foo)\n\n\ndef pytest_unconfigure(config):\n foo = getattr(config, '_foo', None)\n if foo:\n del config._foo\n config.pluginmanager.unregister(foo)\n\n\nclass FooBar(object):\n # add docstrings from test cases to reports\n @pytest.hookimpl(tryfirst=True, hookwrapper=True)\n def pytest_runtest_makereport(self, item, call):\n outcome = yield\n\n # getting the docstrings from functions, run at test set up\n report = outcome.get_result()\n report.description = str(item.function.__doc__)\n test_fn = item.obj\n docstring = getattr(test_fn, '__doc__')\n if docstring:\n report.nodeid = docstring
-
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.
-
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: