def f(): raise StopIteration def g(): yield f() next(g()) expected_output = """ Traceback (most recent call last): File "stopiter.py", line 5, in g yield f() File "stopiter.py", line 2, in f raise StopIteration StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "stopiter.py", line 7, in next(g()) RuntimeError: generator raised StopIteration """