Add scenarios_class: return a test class instead of injecting into the caller module (#545)#814
Draft
golikovichev wants to merge 1 commit into
Draft
Conversation
…pytest-dev#545) scenarios_class parses the feature files like scenarios() but returns a class whose test_* methods run the scenarios, instead of injecting them into the caller module. The generated tests are then visible to editors and linters, and a single scenario can be overridden by subclassing the returned class.
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.
Draft for discussion #545. Opening it early, as discussed, so you can redirect on the API shape before I build out the deprecation path.
What this does
Adds
scenarios_class(*feature_paths, ...), which parses the feature files exactly likescenarios()but returns a class instead of injecting the generated tests into the caller module:The generated tests are now visible to editors and linters, and a single scenario can be overridden by subclassing:
Method names follow the same
test_<scenario name>convention (and the same collision suffixing) asscenarios().Notes and open questions
scenarios_classis provisional. Happy to rename tofeature_testsor whatever reads best to you.@staticmethod. The generated wrapper only takes the request and example fixtures, notself, so the methods are stored as staticmethods and an override has to be a staticmethod too (see the second test). If you would rather the override read as a plain method,@scenariowould need to become method-aware. Wanted your call before going further.DeprecationWarningfromscenarios()pointing at the new API, then drop the injection in the next major so it fails loudly. One wrinkle:pytest.initurnspytest_bddwarnings into errors, so the warning needs the right stacklevel (point at the user module) and the existing suite may need an explicit filter. Happy to do that in a follow-up once the API shape is settled.Tests
scenarios_classreturns a collectable class and runs every scenario.