Skip to content

Incorrect mixture of exit code and jUnit report when pytest.exit is called and a fixture teardown fails #8750

Open
@Hawk777

Description

@Hawk777

Consider the following file:

import pytest

@pytest.fixture(scope="function")
def myfixture():
    print("enter fixture")
    yield
    assert False, "fixture fails in teardown"

def test_foo(myfixture):
    pytest.exit("foo")

Run this with pytest --junit-xml=junit.xml. The exit code is 1, which, per the documentation, means “some of the tests failed”. However, if you examine junit.xml, it does not record any failed tests! I’m not sure whether the exit code ought to be 2 (because of the pytest.exit call) or whether the test teardown ought to be recorded as a failure in junit.xml (because of the assertion failure, and the exit code remain 1 in this case), and I don’t really care that much which one happens, but it ought to be one or the other.

This happened on Pytest 6.2.4 under Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: junitxmlrelated to the junitxml builtin plugintopic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions