Skip to content

Commit

Permalink
Feature/264 pytest71 (#265)
Browse files Browse the repository at this point in the history
* Removed erroneous copyright headers

* Fixed `ImportError` when using `pytest 7.1`. Fixed #264 and pytest-dev/pytest#9762

* Added two easy flake8 fixes

Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
  • Loading branch information
smarie and Sylvain MARIE committed Mar 14, 2022
1 parent 501f9fb commit 976f4a8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 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
3 changes: 2 additions & 1 deletion 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 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
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
@@ -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
@@ -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
@@ -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

0 comments on commit 976f4a8

Please sign in to comment.