Skip to content

Commit

Permalink
Fixed AttributeError issue in is_case_function when an inspected …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
smarie and Sylvain MARIE committed Feb 23, 2023
1 parent d333414 commit ab3b719
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

### 3.6.14 - bugfix
### 3.6.14 - bugfixes

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

### 3.6.13 - bugfix
Expand Down
6 changes: 5 additions & 1 deletion src/pytest_cases/case_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,8 @@ def is_case_function(f, # type: Any
# a function generated by us. ignore this
return False
else:
return f.__name__.startswith(prefix) if check_prefix else True
try:
return f.__name__.startswith(prefix) if check_prefix else True
except:
# GH#287: safe fallback
return False
24 changes: 24 additions & 0 deletions tests/cases/issues/test_py35_issue_287.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Tuple

import pytest_cases


class Cases:
ClassVar1 = int # OK
ClassVar2 = int # OK
ClassVar3 = 1 # OK
ClassVar4 = float # OK

ClassVar5 = Tuple[int] # FAILS with AttributeError: __name__
# ClassVar6 = Tuple[float] # FAILS with AttributeError: __name__
# ClassVar7 = List[int] # FAILS with AttributeError: __name__
# ClassVar8 = Any # FAILS with AttributeError: __name__
# ClassVar9 = Dict[int, str] # FAILS with AttributeError: __name__

def case_b(self):
return 1


@pytest_cases.parametrize_with_cases("case", Cases)
def test_something(case) -> None:
pass

0 comments on commit ab3b719

Please sign in to comment.