radish-bdd / radish

Behavior Driven Development tooling for Python. The root from red to green.
https://radish-bdd.github.io
MIT License
182 stars 49 forks source link

Are step contexts really not passed when calling step.behave_like? #400

Closed edaine closed 4 years ago

edaine commented 4 years ago

Important notices Before you add a new report, we ask you kindly to acknowledge the following:

[+] I have read the contributing guide lines at https://github.com/radish-bdd/radish/blob/master/.github/CONTRIBUTING.md

[+] I have read and respect the code of conduct at https://github.com/radish-bdd/radish/blob/master/.github/CODE_OF_CONDUCT.md

[+] I have searched the existing issues and I'm convinced that mine is new.

Ask your Question So, I'm trying to reuse another step that reads return codes, and inside the step that reads return codes, it uses step.embed. I noticed that when I call the step like this:

        step.behave_like("A return code of 0 is received")

It just leaves a blank space in the report. But when I call the step as a function (I am using a classes to implement my steps) and pass step as a parameter, then the embedding in the report actually works:

        self.read_return_code(step, 0)

I peeked into the code of behave_like and saw that a new Step instance is actually created:

        new_step = Step(None, sentence, self.path, self.line, self.parent, True)
        merge_step(new_step, StepRegistry().steps)

Although I see that self.parent was passed in the constructor, which should take care of passing the context, it still behaves differently.

Are you able to clarify this? I have grouped my steps into classes based on the feature we are testing, so calling step.behave_like helps reuse steps without needing to instantiate the actual class.