I want to wrap the pytest-html plugin in the following way:
I was able to add the option with implementing the pytest_addoption(parser)
function, but got stuck on the 2nd thing...
What I was able to do is this: implement a hook frmo pytest-html. However, I have to access my option X, in order to do what to do. The problem is, pytest-html's hook does not give the "request" object as a param, so I can't access the option value...
Can I have additional args for a hook? or something like this?
You can attach additional data to the report object, for example via a custom wrapper around the pytest_runtest_makereport
hook:
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.config = item.config
Now the config
object will be accessible via report.config
in all reporting hooks, including the ones of pytest-html
:
def pytest_html_report_title(report):
""" Called before adding the title to the report """
assert report.config is not None