Skip to content

How to get all failed tests _just once_ at the end of the session? #12651

Answered by lexicalunit
lexicalunit asked this question in Q&A
Discussion options

You must be logged in to vote

I figured out a workaround but it seems like I'm doing something wrong here because I needed to import from _pytest and access a _session property to do it 🤷🏻‍♀️

import pytest
from _pytest.terminal import TerminalReporter

def pytest_terminal_summary(terminalreporter: TerminalReporter, exitstatus: int) -> None:
    if exitstatus == pytest.ExitCode.OK:
        return
    session: pytest.Session | None = terminalreporter._session
    if session is None:
        return

    should_do_the_thing = False
    failures: set[str] = {failure.nodeid for failure in terminalreporter.getreports("failed")}
    for item in session.items:
        if not item.get_closest_marker("failure_triggers_do_the_thing"

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by wimglenn
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@nicoddemus
Comment options

@lexicalunit
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants