Skip to content

Commit bfbc8e4

Browse files
committed
Test that teardown is invoked when another fixture fails
1 parent d3188a1 commit bfbc8e4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_fixture.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,3 +499,32 @@ async def test_b(shared_fixture):
499499
# https://github.com/willemt/pytest-asyncio-cooperative/issues/42
500500
else:
501501
result.assert_outcomes(passed=2)
502+
503+
504+
def test_teardown_on_fixture_error(testdir):
505+
testdir.makepyfile(
506+
"""
507+
import pytest
508+
509+
import asyncio
510+
from warnings import warn
511+
512+
@pytest.fixture
513+
async def fixture_ok():
514+
await asyncio.sleep(1)
515+
yield
516+
warn("fixture_ok teardown")
517+
518+
@pytest.fixture
519+
async def fixture_fail():
520+
await asyncio.sleep(2)
521+
assert False
522+
523+
@pytest.mark.asyncio_cooperative
524+
async def test(fixture_ok, fixture_fail):
525+
assert True
526+
"""
527+
)
528+
529+
with pytest.warns(UserWarning, match="fixture_ok teardown"):
530+
result = testdir.runpytest()

0 commit comments

Comments
 (0)