pytest-bdd
pytest-bdd copied to clipboard
Use of _getframe in get_caller_module_locals (without being able to specify depth) can be problematic
Hello,
First I would like to thank all the maintainers for working on this project, it has been very helpful for our organization, thank you.
I am playing with adding intermediate decorators and wrappers for the step_type functions (when, then, and given) to improve convenience but if I call them from a function inside the steps.py, the step function is not found because the stack frame retrieved by sys._getframe is not the one for the module steps.py which is where the fixtures (and thereby steps) are looked for, so the step gets added to the incorrect f_locals (the function I am calling the step_type from). I was wondering if there is any plan to open up the depth option to be more accessable for situations like this? Or, better yet, maybe avoid this mechanism all together (maybe find the module steps.py some other way).
Thanks
https://github.com/pytest-dev/pytest-bdd/blob/048da9e87a1f504aa7e1686a31710d33816e4c3c/pytest_bdd/steps.py#L132
Hi! This was discussed a few times #296, #310, but no decision was made. You could provide PR with your vision of how it could be.
BTW you could monkey patch call to get_caller_module_locals() at pytest_bdd.steps._step_decorator using unittest.patch with needed depth
https://github.com/pytest-dev/pytest-bdd/pull/540 should fix this
Fixed by https://github.com/pytest-dev/pytest-bdd/pull/548