diff --git a/tests/test_ended_by_exception.py b/tests/test_ended_by_exception.py index b8fc963..e633a72 100644 --- a/tests/test_ended_by_exception.py +++ b/tests/test_ended_by_exception.py @@ -5,9 +5,11 @@ f_lasti can be -1, and co_code[-1] would read the wrong opcode and misreport a normal return as "Call ended by exception". """ +import io import opcode from unittest.mock import Mock +import pysnooper from pysnooper.tracer import call_ended_by_exception @@ -39,3 +41,22 @@ def test_last_opcode_not_return_is_exception(): def test_non_return_event_is_never_exception(): co_code = bytes([opcode.opmap["NOP"], 0]) assert call_ended_by_exception(_frame(co_code, 0), "call", None) is False + + +def test_unstarted_generator_close_is_not_an_exception(): + string_io = io.StringIO() + + def gen(n): + for i in range(n): + yield i + + @pysnooper.snoop(string_io, depth=2, color=False) + def main(): + g = gen(5) + g.close() + return 42 + + assert main() == 42 + output = string_io.getvalue() + assert "Call ended by exception" not in output + assert "Return value:.. 42" in output