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

Use of _getframe in get_caller_module_locals (without being able to specify depth) can be problematic #464

Closed
cvahid-nih opened this issue Dec 7, 2021 · 3 comments

Comments

@cvahid-nih
Copy link

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

caller_locals = get_caller_module_locals()

@elchupanebrej
Copy link

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

@youtux
Copy link
Contributor

youtux commented Jul 15, 2022

#540 should fix this

@youtux
Copy link
Contributor

youtux commented Aug 19, 2022

Fixed by #548

@youtux youtux closed this as completed Aug 19, 2022
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

3 participants