feat: use scenarios() shortcut in code generation template (take 2)#825
Open
Pierre-Sassoulas wants to merge 3 commits into
Open
feat: use scenarios() shortcut in code generation template (take 2)#825Pierre-Sassoulas wants to merge 3 commits into
Pierre-Sassoulas wants to merge 3 commits into
Conversation
Replace individual @Scenario() decorators with the scenarios() shortcut function in the code generation template. This produces cleaner, more concise generated test code. Before: @Scenario('feature.feature', 'Scenario 1') def test_scenario_1(): ... @Scenario('feature.feature', 'Scenario 2') def test_scenario_2(): ... After: scenarios('feature.feature') Closes #535 Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
- Move the feature_paths computation next to the loop that uses it, inside the 'if features' block (review comment from youtux). - Add a test proving generation is idempotent: invoking the script twice yields identical output, and applying the generated code twice to the same module does not duplicate tests (scenarios() skips already bound scenarios). - Add the changelog entry that was missing from #796.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #825 +/- ##
==========================================
+ Coverage 96.12% 96.17% +0.05%
==========================================
Files 55 55
Lines 2423 2432 +9
Branches 136 136
==========================================
+ Hits 2329 2339 +10
Misses 57 57
+ Partials 37 36 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
youtux
reviewed
Jul 5, 2026
| def test_${ make_python_name(scenario.name)}(): | ||
| ${make_python_docstring(scenario.name)} | ||
| <% | ||
| feature_paths = sorted(set(f.rel_filename for f in features)) |
| ) | ||
|
|
||
| first = pytester.run("pytest-bdd", "generate", "idempotency.feature") | ||
| second = pytester.run("pytest-bdd", "generate", "idempotency.feature") |
Contributor
There was a problem hiding this comment.
Oh I thought this script was writing to a file... if not then this test is irrelevant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-applies #796 (reverted in #824 because it was merged before review comments were addressed), with @youtux's review comments addressed:
featuresvsscenariosvar: kept the fix from the original PR — the template iterates overfeaturesdirectly.<% feature_paths = ... %>computation now sits right before the loop that uses it, inside the% if features:block, instead of at the top of the file (comment).test_generate_is_idempotent):feature_pathsis asorted(set(...)), so deterministic);scenarios()skips scenarios already bound in the caller module.Also adds the changelog entry that was missing from the original PR.
Original work by @toroleapinc.
Closes #535