pytest-dev / pytest-dev/pytest

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

Open
#8,750 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: junitxml topic: fixtures type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with pytest --junit-xml=junit.xml, focusing on the interaction between pytest.exit, fixture teardown, and JUnit reporting. Trace the relevant pytest.exit and fixture-teardown entry points, then verify that the resulting exit code and junit.xml consistently represent the failure or exit condition.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.