Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collect markers? #71

Closed
d-chambers opened this issue Jan 8, 2022 · 2 comments
Closed

collect markers? #71

d-chambers opened this issue Jan 8, 2022 · 2 comments

Comments

@d-chambers
Copy link

Hi,

First, great work on this plugin. We were using an older xml format and this has made things way nicer.

I am looking for a way to add markers of each node into the report. Right now I have implemented this like so:

def pytest_sessionfinish(session):
    """
    A hook called after running all tests and collecting results.
    """
    # Bail out early if we aren't generating the json report.
    if not session.config.getoption('json_report'):
        return
    # get the json report and add a dict of {marker_name: [node, ...]}
    report = session.config._json_report.report
    out = collections.defaultdict(list)
    for item in session.items:
        for marker in item.iter_markers():
            out[marker.name].append(item.nodeid)
    report['markers'] = dict(out)

but there is probably a better way. For me, it is important to collect markers for all tests, even the skipped ones. Would adding something about markers to the default output be worthwhile?

@d-chambers
Copy link
Author

Ah, never mind. I see the markers are contained in the keywords of the test items. That is probably good enough.

@numirias
Copy link
Owner

numirias commented Jan 15, 2022

Unless I had overlooked it back then, historically a node's markers were only provided as strings within the list of keywords.

Now that they are available as separate structures and easily iterable, there is a strong case for providing an explicit markers member for test items in the JSON report. So thanks for pointing that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants