radish-bdd / radish

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

Retrieving Scenario Name for logging #424

Closed 51n15t9r closed 3 years ago

51n15t9r commented 3 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 Ask your question here! If the question is related to a particular environment or behavior please make sure to add some context. Hi,

I was wondering if it's possible to get the Scenario description (name/text/id) inside the step python code. I've looked at the code and the documentation and could not find any API that allows me to do this.

If there's already some way to achieve this, can you point me to the documentation/code section?

timofurrer commented 3 years ago

It's possible by just access scenario.sentence for the name, scenario.id for the id, ...

More or less everything which is passed to the ctor here: https://github.com/radish-bdd/radish/blob/bc8b9d174ac735d54558f1513f3f567af5d6a428/radish/scenario.py#L18

That is for the currently stable version of radish.

51n15t9r commented 3 years ago

A Call to "print(scenario.sentence)" inside the step implementation, returns the following error -

File "/usr/local/lib/python3.6/site-packages/radish/stepmodel.py", line 122, in run self.definition_func(self, *args) # pylint: disable=not-callable

Same for other parameters in the ctor.

Full Stack Trace below -: File "/usr/local/bin/radish", line 8, in sys.exit(main()) File "/usr/local/lib/python3.6/site-packages/radish/errororacle.py", line 61, in _decorator return func(*args, kwargs) File "/usr/local/lib/python3.6/site-packages/radish/main.py", line 223, in main return method(core) File "/usr/local/lib/python3.6/site-packages/radish/main.py", line 87, in run_features return runner.start(core.features_to_run, marker=world.config.marker) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 34, in _decorator return func(self, *args, *kwargs) # pylint: disable=not-callable File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 56, in _wrapper return func(self, model_instance, args, kwargs) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 89, in start returncode |= self.run_feature(feature) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 34, in _decorator return func(self, *args, kwargs) # pylint: disable=not-callable File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 56, in _wrapper return func(self, model_instance, *args, *kwargs) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 113, in run_feature returncode |= self.run_scenario(scenario) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 34, in _decorator return func(self, args, kwargs) # pylint: disable=not-callable File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 56, in _wrapper return func(self, model_instance, *args, kwargs) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 137, in run_scenario returncode |= self.run_step(step) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 34, in _decorator return func(self, *args, *kwargs) # pylint: disable=not-callable File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 56, in _wrapper return func(self, model_instance, args, kwargs) File "/usr/local/lib/python3.6/site-packages/radish/runner.py", line 158, in run_step state = step.run() File "/usr/local/lib/python3.6/site-packages/radish/stepmodel.py", line 122, in run self.definition_func(self, *args) # pylint: disable=not-callable

51n15t9r commented 3 years ago

Thanks for pointing in the right direction. Got it working with : print(step.parent.sentence)