Skip to content
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

yield <step-name> does not work without extra yield at the top of the test case #53

Open
danielFlemstrom opened this issue Oct 5, 2022 · 2 comments

Comments

@danielFlemstrom
Copy link

danielFlemstrom commented Oct 5, 2022

Trying out the example from documentation python-pytest-steps/, a hint is given to add the step name to yield.
The code on the documentation shown below needs to be complemented with an extra yield (line 13) in the following image.
image

@danielFlemstrom
Copy link
Author

Digging deeper into this matter, it looks like the steps are handled differently inside VSCODE and when run on the commandline.

When running the above snippet in VSCODE an extra yield at the top works fine although the steps are enumerated in random order in the drop down menu of VSCODE. I extended the test case from the documentation:

image

Starting the test case in VSCODE, they are started like this without the first yield

> ./.venv/bin/python -m pytest --rootdir . --override-ini junit_family=xunit1 --junit-xml=/var/folders/pt/zw8ycd8x1pl7w13s9ltgrvlc0000gq/T/tmp-361377bjf1ByIrKIL.xml ./tests/integration/apis/test_user_files.py::test_suite[4.step_d] cwd: .
I.e. one line per step, repeated In the order d,e,b,a,c.

And fails with:
´./tests/integration/apis/test_user_files.py::test_suite[3.step_c] Failed: [undefined]pytest_steps.steps_generator.StepYieldError: Error collecting results from step '3.step_c': received '1.step_a' from the yield statement, which is different from the current step or step name. Please either use yield, yield '3.step_c' or wrap your step with with optional_step(...) as my_step: and use yield my_step´

Running the same test case from the command line with ´pytest´ works fine though.

This is actually a huge problem for us using VSCODE and a CI/CD pipeline. Any suggestions or ideas are more than welcome!

@smarie
Copy link
Owner

smarie commented Mar 3, 2023

Hi @danielFlemstrom, thanks for reporting !
It seems indeed very much related to VSCode...
Proably the best and fastest workaround is to get rid of pytest steps and instead passing a session-scoped fixture to all of your "steps" tests. You can then further use a basic test class to wrap the various "step" tests, if you want to have them nicely separated from others.

That's the easiest workaround I would suggest, not requiring strong investigations on how VSCode inspects pytest (which I do not have the bandwidth to perform as of now unfortunately)

I hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants