Skip to content

Fix data_consumer generator exhaustion when decorators are stacked - #6

Merged
paveldedik merged 2 commits into
masterfrom
pd/fix-data-consumer-generator
May 11, 2026
Merged

Fix data_consumer generator exhaustion when decorators are stacked#6
paveldedik merged 2 commits into
masterfrom
pd/fix-data-consumer-generator

Conversation

@paveldedik

Copy link
Copy Markdown
Member

A generator expression passed to @data_consumer is a one-shot iterator. When stacked decorators create an outer loop, the inner generator was fully consumed on the first pass and silently yielded nothing on subsequent passes, dropping test combinations without any error.

Fix: materialize generator arguments into lists at decoration time so they can be re-iterated for each outer-loop pass.

Comment thread germanium/decorators.py
"""

output_name = data_provider_kwargs.pop('_output_name', None)
if isinstance(callable_or_property_or_str, types.GeneratorType):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the fix, this is how it behaved:

@data_consumer([True, False], _output_name='flag')
@data_consumer((x for x in [1, 2, 3]), _output_name='number')
def test_something(self, number, flag):
   print(number, flag)

It would print:

1 True
2 True
3 True

The workaround would be using a list comprehension instead of a generator:

@data_consumer([x for x in [1, 2, 3]], _output_name='number')

Anyway, after this fix, it works just fine:

1 True
2 True
3 True
1 False
2 False
3 False

paveldedik added 2 commits May 7, 2026 15:54
A generator expression passed to @data_consumer is a one-shot iterator.
When stacked decorators create an outer loop, the inner generator was fully
consumed on the first pass and silently yielded nothing on subsequent passes,
dropping test combinations without any error.

Fix: materialize generator arguments into lists at decoration time so they
can be re-iterated for each outer-loop pass.
@paveldedik
paveldedik force-pushed the pd/fix-data-consumer-generator branch from e293cd5 to b95595d Compare May 7, 2026 13:55
@paveldedik
paveldedik merged commit 9e5bacf into master May 11, 2026
1 check passed
@paveldedik
paveldedik deleted the pd/fix-data-consumer-generator branch May 11, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants