Closed
Description
Description of the bug
When assertions fail inside a test, context managers don't work.
Test code
from contextlib import contextmanager
@contextmanager
def hello():
print("this runs")
yield
print("this doesn't run")
def test_hello():
with hello():
assert 1 == 0
Running the above code with pytest -s yields
> pytest -s
======================== test session starts ========================
platform linux -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /home/parantapa/workspace/pytest_test, inifile:
collected 1 item
test_basic.py this runs
F
============================= FAILURES ==============================
____________________________ test_hello _____________________________
def test_hello():
with hello():
> assert 1 == 0
E assert 1 == 0
test_basic.py:11: AssertionError
===================== 1 failed in 0.03 seconds ======================
pip list
of the virtual environment
pip list
attrs (17.4.0)
more-itertools (4.1.0)
pip (9.0.3)
pluggy (0.6.0)
py (1.5.3)
pytest (3.5.0)
setuptools (39.0.1)
six (1.11.0)
wheel (0.31.0)
pytest and operating system versions
pytest=3.5.0, python=3.6, OS=ArchLinux