Closed swaingankar closed 5 years ago
Right now, you can use hooks to access the report after it's finished and just save it yourself.
The plugin offers pytest_json_modifyreport
to do something with the final report. E.g., put this in your conftest.py
:
import json
def pytest_json_modifyreport(json_report):
filename = '{}.json'.format(json_report['created'])
with open(filename, 'w') as f:
json.dump(json_report, f, default=str)
You can also employ the builtin pytest_sessionfinish
hook to access the report object (same idea):
def pytest_sessionfinish(session):
# Once the session has finished, the report will be available here
report = session.config._json_report.report
# Do something with the report...
To prevent the report from being saved twice, you could then run the plugin with --json-report-file /dev/null
.
Right now, I'm making major changes to the plugin and this will probably also become easier. So if you can wait a few days, I might have an even more straightforward approach for you.
Thanks a lot for your response, will use the available hooks to get my problem resolved.
Eagerly waiting for your next release, closing the issue.
Just to let you know, a new version has been released. (Be aware that there are some changes, such as minor adjustments in the JSON report format.)
I recommend the following to save your report to a custom path:
--json-report-file none
. This will keep the report from being saved automatically.Use a hook as follows:
def pytest_sessionfinish(session):
plugin = session.config._json_report
plugin.save_report('/my/custom/path.json')
Hello,
Thanks a lot for such a quick turn-around, was away from my work, thus some delay in response.
Will test further and revert in case of any questions.
I need to have the json report loaded to Elasticsearch and thus need to save the JSON with specific test run name, however this is not possible with the current option.
Can you please help