Skip to content

Commit 18fa41d

Browse files
author
Sylvain MARIE
committed
A case id can now be a reserved keyword without triggering any SyntaxError, even if the case is transformed into a fixture. Fixes #230
1 parent d858f6b commit 18fa41d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 3.6.4 - Bugfix
4+
5+
- 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)
6+
37
### 3.6.3 - Bugfix
48

59
- 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)

pytest_cases/common_others.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE>
55
import functools
66
import inspect
7+
from keyword import iskeyword
78
import makefun
89
from importlib import import_module
910
from inspect import findsource
@@ -553,7 +554,12 @@ def make_identifier(name # type: str
553554
"""Transform the given name into a valid python identifier"""
554555
if not isinstance(name, string_types):
555556
raise TypeError("name should be a string, found : %r" % name)
556-
elif isidentifier(name):
557+
558+
if iskeyword(name):
559+
# reserved keywords: add an underscore
560+
name = name + "_"
561+
562+
if isidentifier(name):
557563
return name
558564
elif len(name) == 0:
559565
# empty string
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pytest_cases import parametrize_with_cases
2+
3+
4+
class FooCases:
5+
6+
def case_None(self, tmpdir):
7+
return 1
8+
9+
def case_True(self, tmpdir):
10+
return 1
11+
12+
def case_False(self, tmpdir):
13+
return 1
14+
15+
16+
@parametrize_with_cases("foo", cases=FooCases)
17+
def test_issue_230(foo):
18+
pass

0 commit comments

Comments
 (0)