Skip to content

Commit

Permalink
Fixed ImportError when using pytest 7.1. Fixed #264 and pytest-de…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain MARIE committed Mar 14, 2022
1 parent 8bb5378 commit 69f438b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
@@ -1,5 +1,9 @@
# Changelog

### 3.6.10 - bugfix for pytest 7.1

- Fixed `ImportError` when using `pytest 7.1`. Fixed [#264](https://github.com/smarie/python-pytest-cases/issues/264) and [pytest-dev#9762](https://github.com/pytest-dev/pytest/issues/9762).

### 3.6.9 - Bugfix with pytest 7

- Fixed `FrozenInstanceError` when using `pytest 7.0.0`. Fixed [#251](https://github.com/smarie/python-pytest-cases/issues/251). [PR#253](https://github.com/smarie/python-pytest-cases/pull/253) by [jammer87](https://github.com/jammer87)
Expand Down
36 changes: 21 additions & 15 deletions src/pytest_cases/common_pytest.py
Expand Up @@ -30,7 +30,7 @@
from .common_others import get_function_host
from .common_pytest_marks import make_marked_parameter_value, get_param_argnames_as_list, \
get_pytest_parametrize_marks, get_pytest_usefixture_marks, PYTEST3_OR_GREATER, PYTEST6_OR_GREATER, \
PYTEST38_OR_GREATER, PYTEST34_OR_GREATER, PYTEST33_OR_GREATER, PYTEST32_OR_GREATER
PYTEST38_OR_GREATER, PYTEST34_OR_GREATER, PYTEST33_OR_GREATER, PYTEST32_OR_GREATER, PYTEST71_OR_GREATER
from .common_pytest_lazy_values import is_lazy_value, is_lazy


Expand Down Expand Up @@ -554,22 +554,28 @@ def set_callspec_arg_scope_to_function(callspec, arg_name):
callspec._arg2scopenum[arg_name] = get_pytest_function_scopeval() # noqa


from _pytest.python import _idval # noqa
if PYTEST71_OR_GREATER:
from _pytest.python import IdMaker # noqa

if PYTEST6_OR_GREATER:
_idval_kwargs = dict(idfn=None,
nodeid=None, # item is not used in pytest(>=6.0.0) nodeid is only used by idfn
config=None # if a config hook was available it would be used before this is called)
)
elif PYTEST38_OR_GREATER:
_idval_kwargs = dict(idfn=None,
item=None, # item is only used by idfn
config=None # if a config hook was available it would be used before this is called)
)
_idval = IdMaker([], [], None, None, None, None, None)._idval
_idval_kwargs = dict()
else:
_idval_kwargs = dict(idfn=None,
# config=None # if a config hook was available it would be used before this is called)
)
from _pytest.python import _idval # noqa

if PYTEST6_OR_GREATER:
_idval_kwargs = dict(idfn=None,
nodeid=None, # item is not used in pytest(>=6.0.0) nodeid is only used by idfn
config=None # if a config hook was available it would be used before this is called)
)
elif PYTEST38_OR_GREATER:
_idval_kwargs = dict(idfn=None,
item=None, # item is only used by idfn
config=None # if a config hook was available it would be used before this is called)
)
else:
_idval_kwargs = dict(idfn=None,
# config=None # if a config hook was available it would be used before this is called)
)


def mini_idval(
Expand Down
1 change: 1 addition & 0 deletions src/pytest_cases/common_pytest_marks.py
Expand Up @@ -42,6 +42,7 @@
PYTEST421_OR_GREATER = PYTEST_VERSION >= LooseVersion('4.2.1')
PYTEST6_OR_GREATER = PYTEST_VERSION >= LooseVersion('6.0.0')
PYTEST7_OR_GREATER = PYTEST_VERSION >= LooseVersion('7.0.0')
PYTEST71_OR_GREATER = PYTEST_VERSION >= LooseVersion('7.1.0')


def get_param_argnames_as_list(argnames):
Expand Down

0 comments on commit 69f438b

Please sign in to comment.