Skip to content

Fix --generate-missing reporting defined background steps as missing - #843

Open
taltal-beep wants to merge 3 commits into
pytest-dev:masterfrom
taltal-beep:fix/generate-missing-shared-background
Open

taltal-beep wants to merge 3 commits into
pytest-dev:masterfrom
taltal-beep:fix/generate-missing-shared-background

Conversation

@taltal-beep

Copy link
Copy Markdown

parse_feature_files() collects scenario.steps for every scenario, and those include the feature's (and rule's) background steps, so each background Step object is listed once per scenario. Step uses eq=False, so _show_missing_code_main removes only one copy when a bound test defines it, and steps of unbound scenarios are skipped if they belong to a background. So as soon as a feature with a background has an unbound scenario, a background step that is defined gets reported as "Background step … is not defined", a stub is generated for it, and the exit code is 100.

Repro:

Feature: Missing code generation with a background
    Background:
        Given I have a foobar
    Scenario: Bound scenario
        Given I have a bar
    Scenario: Unbound scenario
        Given I have a bar

with I have a foobar and I have a bar defined and only "Bound scenario" bound: pytest --generate-missing --feature generation.feature prints an @given('I have a foobar') stub.

This keeps each step object only once (dict.fromkeys, identity-based because of eq=False) and adds a regression test with one bound and one unbound scenario. The test fails on master and passes with the change. Full suite passes (147), pre-commit (ruff check/format) and mypy are clean. Changelog entry added under Unreleased / Fixed.

parse_feature_files() listed each background Step object once per
scenario. Binding a scenario removed only one copy, and steps of unbound
scenarios are dropped only if they are not background steps, so a
defined background step was reported (and a stub generated for it) as
soon as the feature had an unbound scenario. Keep each step object once.

This branch has not been deployed

No deployments
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.

1 participant