Closed 15klli closed 3 years ago
You can get missing information via other hooks. If you need the session
object, take it from pytest_sessionstart
, e.g.:
state = {}
def pytest_sessionstart(session):
state['session'] = session
def pytest_json_modifyreport(json_report):
json_report['startdir'] = state['session'].startdir
Many pytest plugins store a reference to the current session in a similar way, e.g.:
class MyPlugin:
def __init__(self, ...):
self._session = None
def pytest_sessionstart(self, session):
self._session = session
... # access the session via self._session when needed
I'm reluctant to add session
to the hookspec args as it seems somewhat arbitrary since report
, config
, etc. may be just as useful in other cases.
pytest_json_modify_report
, I was limited to change it according to the data in the json_report. I don't think it's a good idea. I think if add thepytest.session
param as input, it will give the user more choices to customize their report