Add custom pytest collector for BDD feature files #3863
Merged
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.
pytest-bdd is mostly awesome but I badly miss behave's ability to show and select tests by feature file. When a BDD test under pytest-bdd fails, it is an utter pain to find the feature file with the source of the scenario.
This PR uses pytest collection hooks to manually collect feature files into pytest collection items and annotate them with the feature file name. So instead of reporting a rather meaningless:
we now get
And when running in verbose mode, there are even line numbers:
You can run a single feature file using expression matching:
Running a single scenario is sadly a bit less straightforward but still works:
Only works with pytest >= 8.0. Older versions of pytest will still work but keep using pytest-bdd's default collector.