From 69f438bf9b1c6f190ce1767b04cfebf9d2cd6a74 Mon Sep 17 00:00:00 2001 From: Sylvain MARIE Date: Mon, 14 Mar 2022 10:11:49 +0100 Subject: [PATCH] Fixed `ImportError` when using `pytest 7.1`. Fixed #264 and https://github.com/pytest-dev/pytest/issues/9762 --- docs/changelog.md | 4 +++ src/pytest_cases/common_pytest.py | 36 ++++++++++++++----------- src/pytest_cases/common_pytest_marks.py | 1 + 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index d8f854ec..64cdb085 100644 --- a/docs/changelog.md +++ b/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) diff --git a/src/pytest_cases/common_pytest.py b/src/pytest_cases/common_pytest.py index af0f35ca..82a85a9c 100644 --- a/src/pytest_cases/common_pytest.py +++ b/src/pytest_cases/common_pytest.py @@ -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 @@ -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( diff --git a/src/pytest_cases/common_pytest_marks.py b/src/pytest_cases/common_pytest_marks.py index 6cf6ce7e..6b450340 100644 --- a/src/pytest_cases/common_pytest_marks.py +++ b/src/pytest_cases/common_pytest_marks.py @@ -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):