Skip to content

Count teardown error as fail #702

Closed
Closed
@ego-thales

Description

@ego-thales

Hi everyone,

Consider this:

import pytest

@pytest.fixture
def foo():
    yield
    raise

def test_a(): raise
def test_b(foo): ...

It provides this report:

$ pytest [...]/tmp.py
=============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0
rootdir: ********
plugins: cov-6.2.1
collected 2 items                                                                                                                                                                                                 

[...]/tmp.py F.E                                                                                                                                                                                  [100%]

===================================================================================================== ERRORS ======================================================================================================
___________________________________________________________________________________________ ERROR at teardown of test_b ___________________________________________________________________________________________

    @pytest.fixture
    def foo():
        yield
>       raise
E       RuntimeError: No active exception to reraise

[...]/tmp.py:6: RuntimeError
==================================================================================================== FAILURES =====================================================================================================
_____________________________________________________________________________________________________ test_a ______________________________________________________________________________________________________

>   def test_a(): raise
                  ^^^^^
E   RuntimeError: No active exception to reraise

[...]/tmp.py:8: RuntimeError
============================================================================================= short test summary info =============================================================================================
FAILED [...]/tmp.py::test_a - RuntimeError: No active exception to reraise
ERROR [...]/tmp.py::test_b - RuntimeError: No active exception to reraise
====================================================================================== 1 failed, 1 passed, 1 error in 0.07s =======================================================================================
$

As you can see, test_b PASSED but there was an error in teardown of foo. Is it possible to make it so that foo fails test_b? I tried pytest.fail() but it behaves the same.

If it is not possible, I think it would be nice to consider!

All the best.
Élie.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions