numirias / pytest-json-report

🗒️ A pytest plugin to report test results as JSON
MIT License
147 stars 39 forks source link

Add additional fields to the report? #4

Closed jacebrowning closed 6 years ago

jacebrowning commented 6 years ago

Is there any way to insert additional fields into each test's JSON object?

Specifically, I am capturing my own logs during each test and would like to make the path to each of these log files available in the report.

numirias commented 6 years ago

That's not currently possible but definitely a useful addition! Should be quick to implement, I'll let you know when it's done.

numirias commented 6 years ago

There is now a json_metadata fixture to add metadata to the current test item, e.g.:

def test_something(json_metadata):
    json_metadata['foo'] = {"some": "thing"}

The readme also lists some other ways to customize the report if you want to add more than just per-test metadata. Let me know if that works for you.

jacebrowning commented 6 years ago

I think pytest_json_modifyreport will do what I need. Thanks!

jacebrowning commented 6 years ago

This is working great!

My only complaint is that this large metadata block now appears in my test setup:

Did this plugin add that?

numirias commented 6 years ago

Did this plugin add that?

No, that block is added by pytest-metadata, right here. If you want an option to disable it, you might want to file an issue over there. :)

jacebrowning commented 6 years ago

FYI, clearing the metadata is as simple as:

def pytest_configure(config):
    config._metadata.clear()
numirias commented 6 years ago

Yep, thanks, although I took your question more being about disabling the output in the terminal report, not removing metadata entirely. (I also had submitted a patch over there so that now metadata is only displayed in the terminal report if you use --verbose.) But it's also good to know how to remove it entirely.