Closed j-carson closed 2 years ago
Thanks @j-carson ! This is a very nice way indeed to fix this issue. However if results_bag
is not explicitly declared as a test dependency in your test function, request.getfixturevalue("results_bag")
might not work.
Therefore, I would suggest the following, I suspect that it works too:
@pytest.fixture
@one_fixture_per_step
def step_bag(results_bag):
return results_bag
Do you confirm ?
More generally I think that your proposal could make a great addition to pytest-steps
. However it should be optional: if this fixture is provided by the plugin, and the user does not use it in any of its tests, the user should not need pytest-harvest
to be installed. I think that with the above design, as long as "auto use" is not on, this is the pytest default behaviour. Do you confirm ?
The shorter implementation of step_bag
fixture works for me.
I think that with the above design, as long as "auto use" is not on, this is the pytest default behaviour. Do you confirm ?
I will need to write a test case to verify this second question.
Wrote the test case for above: In a virtualenv with pytest-steps installed but not pytest-harvest, the above fixture will not cause an error if that fixture is not used by any test.
Cool ! Then it seems that all lights are green :) Would you like to propose a PR then ?
The fixture would need to live in module plugin.py
and have at least one dedicated test. If you feel like updating the documentation markdown accordingly
api_reference.md : probably add a subsection under https://smarie.github.io/python-pytest-steps/api_reference/#pytest-harvest-utility-methods
index.md : probably add a subsection under https://smarie.github.io/python-pytest-steps/#3-usage-with-pytest-harvest)
(No need to test the case when the pytest-harvest plugin is not installed, this is a pytest mechanism and it wont change over time).
let me know !
Fixed by #46
I have just started using your pytest extensions - they are wonderful, thank you!
I had a pytest-steps test with four steps, and each step saved the current value of a variable at the end of each step. The results_bag only had the value of the variable at the last step, and that value appeared in the row for the first step.
I fixed it by creating a per-step results bag fixture and using that in place of results_bag as the argument to my test. Is this the best way to get my desired behavior?