-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Step advanced usecases #548
Merged
Merged
+543
−156
Conversation
This file contains 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
Codecov Report
@@ Coverage Diff @@
## master #548 +/- ##
==========================================
+ Coverage 95.17% 95.25% +0.07%
==========================================
Files 48 48
Lines 1680 1708 +28
Branches 206 209 +3
==========================================
+ Hits 1599 1627 +28
Misses 51 51
Partials 30 30
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
1 task
7a6335b
to
d5112d8
Compare
olegpidsadnyi
previously approved these changes
Aug 13, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
8c4b8c6
to
9ecf4bf
Compare
This was referenced Aug 14, 2022
pbarnajc
pushed a commit
to pbarnajc/pytest-bdd
that referenced
this pull request
Jan 31, 2023
Step advanced usecases
pbarnajc
pushed a commit
to pbarnajc/pytest-bdd
that referenced
this pull request
Feb 1, 2023
Step advanced usecases
pbarnajc
pushed a commit
to pbarnajc/pytest-bdd
that referenced
this pull request
Feb 1, 2023
Step advanced usecases
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.
This PR allows for more advanced use cases of the library.
Add generic
@step(...)
decoratorWith this decorator, users can define a step function that will work for Given, When and Then steps:
Add
stacklevel
param to@given
,@when
,@then
,@step
This will let users create functions that generate steps dynamically.
For example, if you use pytest-factoryboy, you can automatically generate steps for the model fixtures like this. This can be very useful when most of the model instance variables can be defined by similar looking "given" steps.
Let's look at a concrete example; let's say you have a class
Wallet
that has some amount for each currency:Pytest-factoryboy will automatically create a model fixture for this class:
Now we can define a function
generate_wallet_steps()
that creates the steps for any wallet fixture (in our case, it will be "wallet" and "second_wallet"):This last file,
wallet_steps.py
, now contains all the step definitions for our "wallet" and "second_wallet" fixtures.We can now define a scenario like this:
and finally a test file that puts it all together and run the scenarios: