Closed Raglar closed 5 years ago
Thanks for reporting.
Did you run pytest with --json-report
? If you run pytest without that flag, it doesn't actually load the plugin and _json_report
will remain undefined.
Also, unrelated, I realized the readme example has a small bug. The line should read:
report = session.config._json_report.report
instead of
report = session.config._json_report
If that doesn't work for you, please let me know which parameters you are running pytest
with.
Thanks for the response. This is the way I'm running pytest and the json report plugin (I'm running it like this because I can run the test file as a simple python script instead of calling pytest or any other command to run them):
plugin = JSONReport()
pytest.main(['-s',
'-v',
'--json-report-summary',
'test_gold.py',
'--jsons_dir', jsons_dir,
'--output_dir', output_dir,
], plugins=[plugin]
)
reportPath=os.path.join(output_dir, 'ut_report.json')
plugin.save_report(reportPath)
Your plugin works like a charm and this code creates the report summary json but I can't access it using pytest_sessionfinish(session)
Thanks for your help looking into this. I fixed the bug and made a new release. Let me know if you still get issues.
It was related to some quirks that occur when running pytest directly from code. Generally, I (and the pytest authors) advise against evoking pytest via pytest.main()
because there are a few things that can go wrong e.g. when plugins are imported more than once or the state doesn't get reset when you run main()
twice. If you still want to run it from your own Python script, you may want to use subprocesses instead.
Hello! Following the documentation I have declared in my conftest file:
but is throwing me this error:
My end-goal here is to raise an Exception after the json report has been created if any of the tests failed