diff options
Diffstat (limited to 'tests/run/generators_py.py')
-rw-r--r-- | tests/run/generators_py.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/run/generators_py.py b/tests/run/generators_py.py index 914252bf4..9ec6991cf 100644 --- a/tests/run/generators_py.py +++ b/tests/run/generators_py.py @@ -387,3 +387,20 @@ def test_yield_in_const_conditional_true(): """ if True: print((yield 1)) + + +def test_generator_scope(): + """ + Tests that the function is run at the correct time + (i.e. when the generator is created, not when it's run) + >>> list(test_generator_scope()) + inner running + generator created + [0, 10] + """ + def inner(val): + print("inner running") + return [0, val] + gen = (a for a in inner(10)) + print("generator created") + return gen |