Skip to content

Commit 5a30ce2

Browse files
author
Sylvain MARIE
committed
Fixed PytestRemovedIn9Warning: Marks applied to fixtures have no effect. Fixed #337
1 parent 8be611a commit 5a30ce2

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 3.8.5 - Suppressed annoying warning with pytest 8
4+
5+
- Fixed `PytestRemovedIn9Warning: Marks applied to fixtures have no effect`. Fixed
6+
[#337](https://github.com/smarie/python-pytest-cases/issues/337)
7+
38
### 3.8.4 - Removed debug logs
49

510
- Reverted `DEBUG` flag used for pytest 8 compatibility. Fixed

src/pytest_cases/common_pytest_marks.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,29 @@ def remove_pytest_mark(f, mark_name):
201201
return f
202202

203203

204-
def get_pytest_parametrize_marks(f):
204+
def get_pytest_parametrize_marks(
205+
f,
206+
pop=False # type: bool
207+
):
205208
"""
206209
Returns the @pytest.mark.parametrize marks associated with a function (and only those)
207210
208211
:param f:
212+
:param pop: boolean flag, when True the marks will be removed from f.
209213
:return: a tuple containing all 'parametrize' marks
210214
"""
211215
# pytest > 3.2.0
212216
marks = getattr(f, 'pytestmark', None)
213217
if marks is not None:
218+
if pop:
219+
delattr(f, 'pytestmark')
214220
return tuple(_ParametrizationMark(m) for m in marks if m.name == 'parametrize')
215221
else:
216222
# older versions
217223
mark_info = getattr(f, 'parametrize', None)
218224
if mark_info is not None:
225+
if pop:
226+
delattr(f, 'parametrize')
219227
# mark_info.args contains a list of (name, values)
220228
if len(mark_info.args) % 2 != 0:
221229
raise ValueError("internal pytest compatibility error - please report")

src/pytest_cases/fixture_core2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def isasyncgenfunction(obj):
4040
from .common_pytest_lazy_values import get_lazy_args
4141
from .common_pytest import get_pytest_parametrize_marks, make_marked_parameter_value, get_param_argnames_as_list, \
4242
combine_ids, is_marked_parameter_value, pytest_fixture, resolve_ids, extract_parameterset_info, make_test_ids
43-
from .common_pytest_marks import PYTEST3_OR_GREATER
43+
from .common_pytest_marks import PYTEST3_OR_GREATER, PYTEST8_OR_GREATER
4444
from .fixture__creation import get_caller_module, check_name_available, WARN, CHANGE
4545
from .fixture_core1_unions import ignore_unused, is_used_request, NOT_USED, _make_unpack_fixture
4646

@@ -423,7 +423,7 @@ def _decorate_fixture_plus(fixture_func,
423423
_make_unpack_fixture(caller_module, unpack_into, name, hook=hook, in_cls=False)
424424

425425
# (1) Collect all @pytest.mark.parametrize markers (including those created by usage of @cases_data)
426-
parametrizer_marks = get_pytest_parametrize_marks(fixture_func)
426+
parametrizer_marks = get_pytest_parametrize_marks(fixture_func, pop=PYTEST8_OR_GREATER)
427427
if len(parametrizer_marks) < 1:
428428
# make the fixture union-aware
429429
wrapped_fixture_func = ignore_unused(fixture_func)

0 commit comments

Comments
 (0)