Skip to content

Commit 0a8ac24

Browse files
committed
Improve coverage
1 parent 29f415e commit 0a8ac24

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/test_insert_pytest_raises.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ def test_insert_pytest_raises_frame_not_found(pytester_pretty, capsys):
111111
pytester_pretty.makeconftest(config)
112112
pytester_pretty.makepyfile(
113113
"""\
114-
import pytest, re
115-
116114
def test_raise_keyerror(insert_pytest_raises):
117115
eval('insert_pytest_raises().__enter__()')
118116
"""
@@ -130,8 +128,6 @@ def test_insert_pytest_raises_called_outside_with(pytester_pretty, capsys):
130128
pytester_pretty.makeconftest(config)
131129
pytester_pretty.makepyfile(
132130
"""\
133-
import pytest, re
134-
135131
def test_raise_keyerror(insert_pytest_raises):
136132
assert insert_pytest_raises().__enter__() == 1
137133
"""
@@ -147,7 +143,7 @@ def test_insert_pytest_raises_called_with_other_with_statements(pytester_pretty,
147143
pytester_pretty.makeconftest(config)
148144
pytester_pretty.makepyfile(
149145
"""\
150-
import pytest, re, contextlib
146+
import contextlib
151147
152148
def test_raise_keyerror(insert_pytest_raises):
153149
with contextlib.nullcontext(), insert_pytest_raises():
@@ -161,3 +157,19 @@ def test_raise_keyerror(insert_pytest_raises):
161157
'RuntimeError: insert_pytest_raises() was called alongside other statements, this is not supported\n'
162158
in captured.out
163159
)
160+
161+
162+
def test_insert_pytest_raises_called_with_no_exception(pytester_pretty, capsys):
163+
os.environ.pop('CI', None)
164+
pytester_pretty.makeconftest(config)
165+
pytester_pretty.makepyfile(
166+
"""\
167+
def test_raise_keyerror(insert_pytest_raises):
168+
with insert_pytest_raises():
169+
assert True
170+
"""
171+
)
172+
result = pytester_pretty.runpytest()
173+
result.assert_outcomes(failed=1)
174+
captured = capsys.readouterr()
175+
assert 'RuntimeError: insert_pytest_raises() was called but no exception was raised\n' in captured.out

0 commit comments

Comments
 (0)