Skip to content

Commit

Permalink
A case id can now be a reserved keyword without triggering any `Synta…
Browse files Browse the repository at this point in the history
…xError`, even if the case is transformed into a fixture. Fixes #230
  • Loading branch information
Sylvain MARIE committed Sep 17, 2021
1 parent d858f6b commit 18fa41d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 3.6.4 - Bugfix

- A case id can now be a reserved keyword without triggering any `SyntaxError`, even if the case is transformed into a fixture. Fixes [#230](https://github.com/smarie/python-pytest-cases/issues/230)

### 3.6.3 - Bugfix

- Fixed an issue where a lazy value would not be resolved. This happens when the "auto-simplify fixture" happens in `@parametrize`. Fixes [#225](https://github.com/smarie/python-pytest-cases/issues/225)
Expand Down
8 changes: 7 additions & 1 deletion pytest_cases/common_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE>
import functools
import inspect
from keyword import iskeyword
import makefun
from importlib import import_module
from inspect import findsource
Expand Down Expand Up @@ -553,7 +554,12 @@ def make_identifier(name # type: str
"""Transform the given name into a valid python identifier"""
if not isinstance(name, string_types):
raise TypeError("name should be a string, found : %r" % name)
elif isidentifier(name):

if iskeyword(name):
# reserved keywords: add an underscore
name = name + "_"

if isidentifier(name):
return name
elif len(name) == 0:
# empty string
Expand Down
18 changes: 18 additions & 0 deletions pytest_cases/tests/cases/issues/test_issue_230.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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

0 comments on commit 18fa41d

Please sign in to comment.