From 00d708b67300a7e9144c91801751c264eb5e75fd Mon Sep 17 00:00:00 2001 From: karlkovaciny Date: Sun, 3 Nov 2019 22:29:51 -0500 Subject: [PATCH] Add hint to error message I was playing with the tutorial at https://smarie.github.io/python-pytest-steps/#c-optional-steps-and-dependencies and got this error. I had indented badly and my code looked like this: with optional_step('step_b') as step_b: assert True yield step_b # should have been unindented, caused this error. I just wanted to help any other newbie get past this in case it happened to them. --- pytest_steps/steps_generator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytest_steps/steps_generator.py b/pytest_steps/steps_generator.py index 4382142..6777f3b 100644 --- a/pytest_steps/steps_generator.py +++ b/pytest_steps/steps_generator.py @@ -310,7 +310,8 @@ def execute(self, step_name, *args, **kwargs): elif isinstance(res, optional_step): # optional step: check if the execution went well if res.exec_result is None: - raise ValueError("Internal error: this should not happen") + raise ValueError("Internal error: this should not happen." + "Did you ``yield step_b`` inside the context manager instead of after it?") elif isinstance(res.exec_result, OptionalStepException): # An exception happened in the optional step. We can now raise it safely