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

fixture does not work with lambdas #278

Closed
vyasr opened this issue Jun 15, 2022 · 7 comments
Closed

fixture does not work with lambdas #278

vyasr opened this issue Jun 15, 2022 · 7 comments

Comments

@vyasr
Copy link
Contributor

vyasr commented Jun 15, 2022

First of all I want to say thanks for a great plugin! I've been making extensive use of it recently. I've found a few minor issues that I wanted to raise, so I wanted to say thank you first!

The problem that I'm running into is that pytest_cases.fixture does not support lambdas, but pytest.fixture does.

import pytest
import pytest_cases

globals()['fix'] = pytest.fixture(lambda: 42)  # Works
globals()['fix2'] = pytest_cases.fixture(lambda: 42)  # Doesn't work

For context, I am basically doing what is described in this comment to dynamically generate fixtures, which is why using a lambda would be nice.

@smarie
Copy link
Owner

smarie commented Jun 18, 2022

Hi @vyasr , thanks a lot for your positive feedback !

Would you mind letting us know the stacktrace and when it happens (module loading time or later ?)
Thanks in advance!

@smarie
Copy link
Owner

smarie commented Jun 19, 2022

I tried on my side and if I use I get the following error at test collection time:

..\.nox\tests-3-9-env-pytest-latest\lib\site-packages\makefun\main.py:629: in _make
    code = compile(body, filename, 'single')
E     File "<makefun-gen-1034>", line 1
E       def <lambda>(request):
E           ^
E   SyntaxError: invalid syntax

This is an error in makefun, not pytest-cases. It seems that it will be closed with this PR: smarie/python-makefun#80

@vyasr
Copy link
Contributor Author

vyasr commented Jun 19, 2022

Yes, that is the correct error and I can confirm that smarie/python-makefun#80 fixes the error when I patch that onto the PYTHONPATH. Thanks! I searched through issues on this repo but I didn't recognize that it was coming from the other package!

@smarie
Copy link
Owner

smarie commented Jun 22, 2022

This should now work with makefun 1.14. Do you confirm ?

@smarie
Copy link
Owner

smarie commented Jun 25, 2022

Closing for now, but feel free to reopen @vyasr

@smarie smarie closed this as completed Jun 25, 2022
@vyasr
Copy link
Contributor Author

vyasr commented Jun 27, 2022

Apologies for the delayed response. Yes, I can confirm that the newest release of makefun solves the problem!

@smarie
Copy link
Owner

smarie commented Jun 27, 2022

Thanks @vyasr !

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

2 participants