-
Notifications
You must be signed in to change notification settings - Fork 39
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
request.getfixturevalue('somevalue') returns lazyvalue #143
Comments
Hi @TheCaffinatedDeveloper ! The principle of One way to solve your issue is to use duck typing ( from pytest_cases.common_pytest_lazy_values import is_lazy
val = request.getfixturevalue('foo')
if is_lazy(val):
val = val.get() Note that I consider adding |
I have an afterthought here: currently |
@smarie Thank you for your timely response and suggestions. I was thinking of checking for the lazy items adhoc but was unaware of the is_lazy method - thank you for pointing me in that direction. I think it is worthwhile adding it to the official api. The current project I work on uses the test method doc string to update test descriptions (that get synced to a cloud requirements tool) during a "setup" phase and I am now parametrizing this doc_string using some of the values from the parameters being passed in via a fixture. Others may be doing the same or want to which is why I think adding it to the api would be worthwhile :) PS. I hope pytest-cases gets incorporated into pytest core and you become rich and famous :) |
Great point, this would stay in line with only needing to call the TC function once and the second call would simply retrieve the value from cache - nice! |
Cool @TheCaffinatedDeveloper thanks for the feedback. I'll do my best when I have some bandwidth again - for now I am in paternity leave so my dev time is fairly limited as you can imagine
:D if open source development was a path to fame and money we would all know it by now :) but I appreciate your kind words and positive feedback, this is a far better reward ! As far as pytest core is concerned, I think that this has been identified by the core team : pytest-dev/pytest#349 (comment) |
@TheCaffinatedDeveloper this will ship with 2.4.0 probably topday when travis wakes up : it seems to be extremely slow these days |
I often use a pattern of performing some additional setup via another fixture by using the "special" request object to introspect the current test method. Once scenario involves using the request.getfixturevalue('foo') which should return the actual value being used in the current context but with pytest_cases I get the lazy object and have to call the .get() to get the value.
The problem is that I am not always using pytest_cases and would like my fixtures to be common and reused where it might not be a lazy object and thus not have a .get method. Perhaps I am doing something wrong, guidance requested please.
The text was updated successfully, but these errors were encountered: