-
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
SyntaxError when a case id is a reserved keyword and the case is transformed into a fixture behind the scenes #230
Comments
Hi there, I found the issue. I had a couple of test cases where I had used a reserved word as the case id - specifically I had used the following as case id's: None, False, True It would be nice to be able to use any string as a case id & not have to worry about this sort of issue. Thanks Tim |
Thanks @wonboyn !! Indeed I was able to reproduce the bug. It arises when a case function is transformed into a fixture, and that fixture gets a name that can not actually be used as an argument name (False, True, None, ... as you pointed out). Here is a reproducible example from pytest_cases import parametrize_with_cases
class FooCases:
def case_None(self, tmpdir):
return 1
def case_True(self, tmpdir):
return 1
def case_False(self, tmpdir):
return 1
@parametrize_with_cases("foo", cases=FooCases)
def test_issue_230(foo):
pass |
Fixed in 3.6.4 to be released soon |
3.6.4 is available. Can you try and let me know ? Thanks ! |
Thanks for that. Works a treat |
Thanks for the feedback @wonboyn ! |
[EDIT] Nevermind, didn't realize 3.x tag/releases also work with python 2.7 |
Hi there,
I've just started getting an error during pytest discovery/collection.
The error is for one specific test function but I'm struggling to understand what the issue is.
When I run discovery, it reports the following error:
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:578: in _importtestmodule mod = import_path(self.fspath, mode=importmode) /usr/local/lib/python3.6/dist-packages/_pytest/pathlib.py:524: in import_path importlib.import_module(module_name) /usr/lib/python3.6/importlib/__init__.py:126: in import_module return _bootstrap._gcd_import(name[level:], package, level) <frozen importlib._bootstrap>:994: in _gcd_import ??? <frozen importlib._bootstrap>:971: in _find_and_load ??? <frozen importlib._bootstrap>:955: in _find_and_load_unlocked ??? <frozen importlib._bootstrap>:665: in _load_unlocked ??? /usr/local/lib/python3.6/dist-packages/_pytest/assertion/rewrite.py:170: in exec_module exec(co, module.__dict__) testing/unit/web/models/test_aws_credential_pool_dao.py:72: in <module> @parametrize_with_cases('val,exp', cases=GetFirstNotUsedTestCases) /usr/local/lib/python3.6/dist-packages/pytest_cases/common_pytest.py:894: in apply return apply_decorator(test_or_fixture_func, container) /usr/local/lib/python3.6/dist-packages/pytest_cases/case_parametrizer_new.py:161: in _apply_parametrization return _parametrize_with_cases(f, host_class_or_module) /usr/local/lib/python3.6/dist-packages/pytest_cases/fixture_parametrize_plus.py:1020: in parametrize_plus_decorate idstyle=_idstyle, scope=scope) /usr/local/lib/python3.6/dist-packages/pytest_cases/fixture_core1_unions.py:379: in _fixture_union @with_signature("%s(%s, request)" % (name, ', '.join(unique_fix_alt_names))) /usr/local/lib/python3.6/dist-packages/makefun/main.py:940: in replace_f **attrs /usr/local/lib/python3.6/dist-packages/makefun/main.py:190: in create_function func_name_from_str, func_signature, func_signature_str = get_signature_from_string(func_signature, evaldict) /usr/local/lib/python3.6/dist-packages/makefun/main.py:441: in get_signature_from_string dummy_f = _make(func_name_, [], body, evaldict) /usr/local/lib/python3.6/dist-packages/makefun/main.py:612: in _make code = compile(body, filename, 'single') E File "<makefun-gen-212>", line 1 E def test_get_first_not_used_val_exp(None, request): E ^ E SyntaxError: invalid syntax ------------------------------------------------------------------- Captured stderr ------------------------------------------------------------------- Error in generated code: def test_get_first_not_used_val_exp(None, request): pass
The test cases class (GetFirstNotUsedTestCases) consists of the following:
`class GetFirstNotUsedTestCases:
`
Any help to figure out what's going wrong would be greatly appreciated.
Cheers
Tim
The text was updated successfully, but these errors were encountered: