Skip to content

Commit ab3b719

Browse files
smarieSylvain MARIE
andauthored
Fixed AttributeError issue in is_case_function when an inspected symbol is a parametrized type hint without __name__ (#294)
* Fixed #292 by dropping the associated nox sessions * Fixed `AttributeError: __name__` issue in `is_case_function` when an inspected symbol comes from the typing package. Fixes #287 --------- Co-authored-by: Sylvain MARIE <[email protected]>
1 parent d333414 commit ab3b719

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

docs/changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
22

3-
### 3.6.14 - bugfix
3+
### 3.6.14 - bugfixes
44

5+
- Fixed `AttributeError` issue in `is_case_function` when an inspected symbol is a parametrized type hint
6+
without `__name__`. Fixes [#287](https://github.com/smarie/python-pytest-cases/issues/287)
57
- Fixed issue with `get_all_cases`: default value for `cases` was wrong. Fixes [#290](https://github.com/smarie/python-pytest-cases/issues/290)
68

79
### 3.6.13 - bugfix

src/pytest_cases/case_funcs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,8 @@ def is_case_function(f, # type: Any
361361
# a function generated by us. ignore this
362362
return False
363363
else:
364-
return f.__name__.startswith(prefix) if check_prefix else True
364+
try:
365+
return f.__name__.startswith(prefix) if check_prefix else True
366+
except:
367+
# GH#287: safe fallback
368+
return False
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from typing import Tuple
2+
3+
import pytest_cases
4+
5+
6+
class Cases:
7+
ClassVar1 = int # OK
8+
ClassVar2 = int # OK
9+
ClassVar3 = 1 # OK
10+
ClassVar4 = float # OK
11+
12+
ClassVar5 = Tuple[int] # FAILS with AttributeError: __name__
13+
# ClassVar6 = Tuple[float] # FAILS with AttributeError: __name__
14+
# ClassVar7 = List[int] # FAILS with AttributeError: __name__
15+
# ClassVar8 = Any # FAILS with AttributeError: __name__
16+
# ClassVar9 = Dict[int, str] # FAILS with AttributeError: __name__
17+
18+
def case_b(self):
19+
return 1
20+
21+
22+
@pytest_cases.parametrize_with_cases("case", Cases)
23+
def test_something(case) -> None:
24+
pass

0 commit comments

Comments
 (0)