Repository: smarie/python-pytest-cases (language: python)

Issue:
PytestRemovedIn9Warning: Marks applied to fixtures have no effect
Hello, and thank you for `pytest_cases`!

With the latest `pytest_cases` (`3.8.3`) and `pytest` (`8.1.1`), we get a deprecation warning when parametrizing fixtures:

```console
(venv) $ tree tests/
tests/
├── conftest.py
└── test_thing.py

0 directories, 2 files
(venv) $ cat tests/conftest.py 
from pytest_cases import fixture, parametrize

@fixture()
@parametrize("hello", ("world", "friend"))
def some_fixture(hello):
    print(hello)

(venv) $ cat tests/test_thing.py 
def test_dummy(some_fixture):
    assert True

(venv) $ pytest tests
==================================================== test session starts =====================================================
platform linux -- Python 3.11.7, pytest-8.1.1, pluggy-1.4.0
rootdir: <redacted>
plugins: cases-3.8.3
collected 2 items                                                                                                            

tests/test_thing.py ..                                                                                                 [100%]

====================================================== warnings summary ======================================================
venv/lib/python3.11/site-packages/pytest_cases/common_pytest.py:47
  /home/bthayer/git/tmp/venv/lib/python3.11/site-packages/pytest_cases/common_pytest.py:47: PytestRemovedIn9Warning: Marks applied to fixtures have no effect
  See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function
    return pytest.fixture(**kwargs)(f)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================ 2 passed, 1 warning in 0.00s ================================================

```


Discussion / hints:

Fix patch:
diff --git a/docs/changelog.md b/docs/changelog.md
index aa91b4d..747576f 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -1,5 +1,10 @@
 # Changelog
 
+### 3.8.5 - Suppressed annoying warning with pytest 8
+
+- Fixed `PytestRemovedIn9Warning: Marks applied to fixtures have no effect`. Fixed
+  [#337](https://github.com/smarie/python-pytest-cases/issues/337)
+
 ### 3.8.4 - Removed debug logs
 
 - Reverted `DEBUG` flag used for pytest 8 compatibility. Fixed


Test patch:
diff --git a/src/pytest_cases/common_pytest_marks.py b/src/pytest_cases/common_pytest_marks.py
index ba83ac1..8fe5037 100644
--- a/src/pytest_cases/common_pytest_marks.py
+++ b/src/pytest_cases/common_pytest_marks.py
@@ -201,21 +201,29 @@ def remove_pytest_mark(f, mark_name):
     return f
 
 
-def get_pytest_parametrize_marks(f):
+def get_pytest_parametrize_marks(
+    f,
+    pop=False  # type: bool
+):
     """
     Returns the @pytest.mark.parametrize marks associated with a function (and only those)
 
     :param f:
+    :param pop: boolean flag, when True the marks will be removed from f.
     :return: a tuple containing all 'parametrize' marks
     """
     # pytest > 3.2.0
     marks = getattr(f, 'pytestmark', None)
     if marks is not None:
+        if pop:
+            delattr(f, 'pytestmark')
         return tuple(_ParametrizationMark(m) for m in marks if m.name == 'parametrize')
     else:
         # older versions
         mark_info = getattr(f, 'parametrize', None)
         if mark_info is not None:
+            if pop:
+                delattr(f, 'parametrize')
             # mark_info.args contains a list of (name, values)
             if len(mark_info.args) % 2 != 0:
                 raise ValueError("internal pytest compatibility error - please report")
diff --git a/src/pytest_cases/fixture_core2.py b/src/pytest_cases/fixture_core2.py
index 43b355e..b41ba47 100644
--- a/src/pytest_cases/fixture_core2.py
+++ b/src/pytest_cases/fixture_core2.py
@@ -40,7 +40,7 @@ def isasyncgenfunction(obj):
 from .common_pytest_lazy_values import get_lazy_args
 from .common_pytest import get_pytest_parametrize_marks, make_marked_parameter_value, get_param_argnames_as_list, \
     combine_ids, is_marked_parameter_value, pytest_fixture, resolve_ids, extract_parameterset_info, make_test_ids
-from .common_pytest_marks import PYTEST3_OR_GREATER
+from .common_pytest_marks import PYTEST3_OR_GREATER, PYTEST8_OR_GREATER
 from .fixture__creation import get_caller_module, check_name_available, WARN, CHANGE
 from .fixture_core1_unions import ignore_unused, is_used_request, NOT_USED, _make_unpack_fixture
 
@@ -423,7 +423,7 @@ def _decorate_fixture_plus(fixture_func,
         _make_unpack_fixture(caller_module, unpack_into, name, hook=hook, in_cls=False)
 
     # (1) Collect all @pytest.mark.parametrize markers (including those created by usage of @cases_data)
-    parametrizer_marks = get_pytest_parametrize_marks(fixture_func)
+    parametrizer_marks = get_pytest_parametrize_marks(fixture_func, pop=PYTEST8_OR_GREATER)
     if len(parametrizer_marks) < 1:
         # make the fixture union-aware
         wrapped_fixture_func = ignore_unused(fixture_func)