Skip to content

Commit 996091e

Browse files
smarieSylvain MARIE
andauthored
Fixed compat with pytest 8.4.0 (#367)
* - Fixed `AttributeError: 'MiniMetafunc' object has no attribute '_params_directness'` when a case function is parametrized or requires a fixtures, with pytest 8.4.0. Fixed #365 - Fixed `ValueError: The provided fixture function does not seem to be a fixture` with `@fixture_ref` with pytest 8.4.0. Fixed #364 * Updated license * Removed useless code in nox file * Removed useless requirement for packaging as setup dependency, and added a few comments/docstring * Added additional combinations in the cicd matrix * Enabled support for python 3.14 --------- Co-authored-by: Sylvain MARIE <[email protected]>
1 parent 94424a1 commit 996091e

File tree

13 files changed

+383
-113
lines changed

13 files changed

+383
-113
lines changed

LICENSE

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2018-2021, Sylvain Marié, Schneider Electric Industries
3+
Copyright (c) 2018-2025, Sylvain Marié, Schneider Electric Industries
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without
77
modification, are permitted provided that the following conditions are met:
88

9-
* Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
1111

12-
* Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
1515

16-
* Neither the name of the copyright holder nor the names of its
17-
contributors may be used to endorse or promote products derived from
18-
this software without specific prior written permission.
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
1919

2020
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2121
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

docs/changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# Changelog
22

3-
### 3.8.7 - compatibility with pytest 8.6.0
3+
### 3.9.0 - support for python 3.14 and pytest 8.6
44

5+
- Fixed `AttributeError: 'MiniMetafunc' object has no attribute '_params_directness'` when a case function is
6+
parametrized or requires a fixtures, with pytest 8.4.0. Fixed
7+
[#365](https://github.com/smarie/python-pytest-cases/issues/365)
8+
- Fixed `ValueError: The provided fixture function does not seem to be a fixture` with `@fixture_ref` with pytest
9+
8.4.0. Fixed [#364](https://github.com/smarie/python-pytest-cases/issues/364)
510
- Dropped support for `python<3.9` and `pytest<6`. Fixes
611
[#362](https://github.com/smarie/python-pytest-cases/issues/362) and fixes
712
[#186](https://github.com/smarie/python-pytest-cases/issues/186)
13+
- Fixed test suite for python 3.14, officializing the support for this version.
814

915
### 3.8.6 - compatibility fix
1016

noxfile.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,26 @@ class Folders:
5151

5252

5353
ENVS = {
54-
# python 3.14 - numpy is not available in precompiled version for this python version yet
55-
# (PY314, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
54+
# python 3.14
55+
(PY314, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
56+
(PY314, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
57+
(PY314, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
5658
# python 3.13
5759
(PY313, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
60+
(PY313, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
61+
(PY313, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
5862
# python 3.12
5963
(PY312, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
6064
(PY312, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
65+
(PY312, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
6166
# python 3.11
62-
# We'll run this last for coverage
67+
# We'll run 'pytest-latest' this last for coverage
68+
(PY311, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
69+
(PY311, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
6370
# python 3.10
6471
(PY310, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
72+
(PY310, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},
73+
(PY310, "pytest6.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<7"}},
6574
# python 3.9
6675
(PY39, "pytest-latest"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": ""}},
6776
(PY39, "pytest7.x"): {"coverage": False, "pkg_specs": {"pip": ">19", "pytest": "<8"}},

src/pytest_cases/case_parametrizer_new.py

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,9 @@ def case_to_argvalues(host_class_or_module, # type: Union[Type, ModuleType]
421421
If `case_fun` requires at least on fixture, a fixture will be created if not yet present, and a `fixture_ref` will
422422
be returned.
423423
424-
If `case_fun` is a parametrized case, one `lazy_value` with a partialized version will be created for each parameter
425-
combination.
424+
If `case_fun` is a parametrized case, (NEW since 3.0.0) a fixture will be created if not yet present,
425+
and a `fixture_ref` will be returned. (OLD < 3.0.0) one `lazy_value` with a partialized version will be created
426+
for each parameter combination.
426427
427428
Otherwise, `case_fun` represents a single case: in that case a single `lazy_value` is returned.
428429
@@ -734,12 +735,27 @@ def extract_cases_from_class(cls,
734735
):
735736
# type: (...) -> List[Callable]
736737
"""
738+
Collects all case functions (methods matching ``case_fun_prefix``) in class ``cls``.
737739
738-
:param cls:
739-
:param check_name:
740-
:param case_fun_prefix:
741-
:param _case_param_factory:
742-
:return:
740+
Parameters
741+
----------
742+
cls : Type
743+
A class where to look for case functions. All methods matching ``prefix`` will be returned.
744+
745+
check_name : bool
746+
If this is ``True`` and class name does not contain the string ``Case``, the class will not be inspected and
747+
an empty list will be returned.
748+
749+
case_fun_prefix : str
750+
A prefix that case functions (class methods) must match to be collected.
751+
752+
_case_param_factory :
753+
Legacy. Not used.
754+
755+
Returns
756+
-------
757+
cases_lst : List[Callable]
758+
A list of collected case functions (class methods).
743759
"""
744760
if is_case_class(cls, check_name=check_name):
745761
# see from _pytest.python import pytest_pycollect_makeitem
@@ -769,7 +785,7 @@ def extract_cases_from_class(cls,
769785
return []
770786

771787

772-
def extract_cases_from_module(module, # type: ModuleRef
788+
def extract_cases_from_module(module, # type: Union[str, ModuleRef]
773789
package_name=None, # type: str
774790
case_fun_prefix=CASE_PREFIX_FUN, # type: str
775791
_case_param_factory=None
@@ -782,10 +798,27 @@ def extract_cases_from_module(module, # type: ModuleRe
782798
See also `_pytest.python.PyCollector.collect` and `_pytest.python.PyCollector._makeitem` and
783799
`_pytest.python.pytest_pycollect_makeitem`: we could probably do this in a better way in pytest_pycollect_makeitem
784800
785-
:param module:
786-
:param package_name:
787-
:param _case_param_factory:
788-
:return:
801+
Parameters
802+
----------
803+
module : Union[str, ModuleRef]
804+
A module where to look for case functions. All functions in the module matching ``prefix`` will be
805+
returned. In addition, all classes in the module with ``Case`` in their name will be inspected. For each of
806+
them, all methods matching ``prefix`` will be returned too.
807+
808+
package_name : Optional[str], default: None
809+
If ``module`` is provided as a string, this is a mandatory package full qualified name (e.g. ``a.b.c``) where
810+
to import the module from.
811+
812+
case_fun_prefix : str
813+
A prefix that case functions (including class methods) must match to be collected.
814+
815+
_case_param_factory :
816+
Legacy. Not used.
817+
818+
Returns
819+
-------
820+
cases : List[Callable]
821+
A list of case functions
789822
"""
790823
# optionally import module if passed as module name string
791824
if isinstance(module, string_types):
@@ -805,12 +838,30 @@ def _extract_cases_from_module_or_class(module=None, # type
805838
cls=None, # type: Type
806839
case_fun_prefix=CASE_PREFIX_FUN, # type: str
807840
_case_param_factory=None
808-
):
841+
): # type: (...) -> List[Callable]
809842
"""
843+
Extracts all case functions from `module` or `cls` (only one non-None must be provided).
810844
811-
:param module:
812-
:param _case_param_factory:
813-
:return:
845+
Parameters
846+
----------
847+
module : Optional[ModuleRef], default: None
848+
A module where to look for case functions. All functions in the module matching ``prefix`` will be
849+
returned. In addition, all classes in the module with ``Case`` in their name will be inspected. For each of
850+
them, all methods matching ``prefix`` will be returned too.
851+
852+
cls : Optional[Type], default: None
853+
A class where to look for case functions. All methods matching ``prefix`` will be returned.
854+
855+
case_fun_prefix : str
856+
A prefix that case functions (including class methods) must match to be collected.
857+
858+
_case_param_factory :
859+
Legacy. Not used.
860+
861+
Returns
862+
-------
863+
cases : List[Callable]
864+
A list of case functions
814865
"""
815866
if not ((cls is None) ^ (module is None)):
816867
raise ValueError("Only one of cls or module should be provided")
@@ -897,6 +948,7 @@ def _of_interest(x): # noqa
897948
% (m, cases_dct[co_firstlineno]))
898949
cases_dct[co_firstlineno] = m
899950
else:
951+
# Not used anymore
900952
# Legacy usage where the cases generators were expanded here and inserted with a virtual line no
901953
_case_param_factory(m, co_firstlineno, cases_dct)
902954

0 commit comments

Comments
 (0)