I'm using pytest bdd to execute bdd scenarios. Example:
Scenario Outline: entry with special character
Given I am an authenticated user
When I request entry information with <entryName> name
Then I expect a 200 response code
And I check the output list contains valid data
Examples:
| entryName |
| #@ |
During the scenario, I create the entry, that I then query for and validate response code/output. I want to be able to cleanup the entry I created regardless of the scenario success (so inserting another row of "Then I clean up my data" won't achieve my goal).
According to https://pytest-bdd.readthedocs.io/en/latest/ - there's a pytest_bdd_after_scenario(request, feature, scenario)
hook that should allow me to execute the cleanup regardless of the scenario success.
- Where should I implement it? (I tried putting it in test_my_scenario.py but it didn't get executed, and according to https://github.com/pytest-dev/pytest-bdd/issues/174 it looks like it should be in conftest?)
- How can I pass a scenario specific argument to the hook? Unlike
pytest_bdd_step_error
it doesn't have func_args in the signature. So how can I clean up the specific entry I created during the scenario?