Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/264 pytest71 #265

Merged
merged 3 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion src/pytest_cases/common_pytest_marks.py
Original file line number Diff line number Diff line change
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 Expand Up @@ -188,7 +189,7 @@ def remove_pytest_mark(f, mark_name):
if marks is not None:
# pytest > 3.2.0
new_marks = [m for m in marks if m.name != mark_name]
setattr(f, 'pytestmark', new_marks)
f.pytestmark = new_marks
else:
# older versions
try:
Expand Down
1 change: 1 addition & 0 deletions src/pytest_cases/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def get_all_fixture_defs(self, drop_fake_fixtures=True, try_to_sort=True):
if PYTEST7_OR_GREATER:
# Scope is an enum, values are in reversed order, and the field is _scope
f_scope = get_pytest_function_scopeval()

def sort_by_scope(kv_pair):
fixture_name, fixture_defs = kv_pair
return fixture_defs[-1]._scope if fixture_defs is not None else f_scope
Expand Down
4 changes: 0 additions & 4 deletions tests/cases/issues/test_issue_238.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Authors: Sylvain MARIE <sylvain.marie@se.com>
# + All contributors to <https://github.com/smarie/python-pyfields>
#
# License: 3-clause BSD, <https://github.com/smarie/python-pyfields/blob/master/LICENSE>
from pytest_cases import parametrize, parametrize_with_cases


Expand Down
4 changes: 0 additions & 4 deletions tests/cases/issues/test_issue_242.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Authors: Sylvain MARIE <sylvain.marie@se.com>
# + All contributors to <https://github.com/smarie/python-pyfields>
#
# License: 3-clause BSD, <https://github.com/smarie/python-pyfields/blob/master/LICENSE>
import pytest
from distutils.version import LooseVersion

Expand Down
4 changes: 0 additions & 4 deletions tests/cases/issues/test_issue_246.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Authors: Sylvain MARIE <sylvain.marie@se.com>
# + All contributors to <https://github.com/smarie/python-pyfields>
#
# License: 3-clause BSD, <https://github.com/smarie/python-pyfields/blob/master/LICENSE>
from distutils.version import LooseVersion

import pytest
Expand Down