Skip to content

Commit a246abd

Browse files
author
Sylvain MARIE
committed
parametrize_plus and fixture_plus are now deprecated in favour of parametrize and fixture, as most users seem to have adopted these names without issues.
1 parent 6801c91 commit a246abd

File tree

7 files changed

+53
-50
lines changed

7 files changed

+53
-50
lines changed

pytest_cases/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
"""Deprecated symbol, for retrocompatibility. Will be dropped soon."""
1010

1111
from .fixture_core1_unions import fixture_union, NOT_USED, unpack_fixture, ignore_unused
12-
from .fixture_core2 import pytest_fixture_plus, fixture_plus, param_fixtures, param_fixture
13-
from .fixture_parametrize_plus import pytest_parametrize_plus, parametrize_plus, fixture_ref
14-
15-
# additional symbols without the 'plus' suffix
16-
parametrize = parametrize_plus
17-
fixture = fixture_plus
12+
from .fixture_core2 import pytest_fixture_plus, fixture_plus, fixture, param_fixtures, param_fixture
13+
from .fixture_parametrize_plus import pytest_parametrize_plus, parametrize_plus, parametrize, fixture_ref
1814

1915

2016
from .case_funcs import case, copy_case_info, set_case_id, get_case_id, get_case_marks, \

pytest_cases/common_pytest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def get_marked_parameter_id(v):
462462
def ParameterSet(values,
463463
id, # noqa
464464
marks):
465-
""" Dummy function (not a class) used only by parametrize_plus """
465+
""" Dummy function (not a class) used only by `parametrize` """
466466
if id is not None:
467467
raise ValueError("This should not happen as `pytest.param` does not exist in pytest 2")
468468

pytest_cases/common_pytest_lazy_values.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def partial_to_str(partialfun):
120120
# noinspection PyPep8Naming
121121
class _LazyValue(Lazy):
122122
"""
123-
A reference to a value getter, to be used in `parametrize_plus`.
123+
A reference to a value getter, to be used in `parametrize`.
124124
125125
A `lazy_value` is the same thing than a function-scoped fixture, except that the value getter function is not a
126126
fixture and therefore can neither be parametrized nor depend on fixtures. It should have no mandatory argument.
@@ -446,7 +446,7 @@ def lazy_value(valuegetter, # type: Callable[[], Any]
446446
marks=() # type: Union[MarkDecorator, Iterable[MarkDecorator]]
447447
):
448448
"""
449-
Creates a reference to a value getter, to be used in `parametrize_plus`.
449+
Creates a reference to a value getter, to be used in `parametrize`.
450450
451451
A `lazy_value` is the same thing than a function-scoped fixture, except that the value getter function is not a
452452
fixture and therefore can neither be parametrized nor depend on fixtures. It should have no mandatory argument.

pytest_cases/common_pytest_marks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def get_parametrize_signature():
7171

7272
class _ParametrizationMark:
7373
"""
74-
Container for the mark information that we grab from the fixtures (`@fixture_plus`)
74+
Container for the mark information that we grab from the fixtures (`@fixture`)
7575
76-
Represents the information required by `@fixture_plus` to work.
76+
Represents the information required by `@fixture` to work.
7777
"""
7878
__slots__ = "param_names", "param_values", "param_ids"
7979

pytest_cases/fixture_core1_unions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ def _fixture_union(fixtures_dest,
347347
**kwargs):
348348
"""
349349
Internal implementation for fixture_union.
350-
The "alternatives" have to be created beforehand, by the caller. This allows `fixture_union` and `parametrize_plus`
351-
to use the same implementation while `parametrize_plus` uses customized "alternatives" containing more information.
350+
The "alternatives" have to be created beforehand, by the caller. This allows `fixture_union` and `parametrize`
351+
to use the same implementation while `parametrize` uses customized "alternatives" containing more information.
352352
353353
:param fixtures_dest:
354354
:param name:
@@ -423,9 +423,9 @@ def unpack_fixture(argnames, # type: str
423423
424424
```python
425425
import pytest
426-
from pytest_cases import unpack_fixture, fixture_plus
426+
from pytest_cases import unpack_fixture, fixture
427427
428-
@fixture_plus
428+
@fixture
429429
@pytest.mark.parametrize("o", ['hello', 'world'])
430430
def c(o):
431431
return o, o[0]

pytest_cases/fixture_core2.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __param_fixture():
113113
if debug:
114114
print("Creating unparametrized fixture %r returning %r" % (argname, argvalue_to_return))
115115

116-
fix = fixture_plus(name=argname, scope=scope, autouse=autouse, ids=ids, hook=hook, **kwargs)(__param_fixture)
116+
fix = fixture(name=argname, scope=scope, autouse=autouse, ids=ids, hook=hook, **kwargs)(__param_fixture)
117117
else:
118118
# create the fixture - set its name so that the optional hook can read it easily
119119
@with_signature("%s(request)" % argname)
@@ -123,8 +123,8 @@ def __param_fixture(request):
123123
if debug:
124124
print("Creating parametrized fixture %r returning %r" % (argname, argvalues))
125125

126-
fix = fixture_plus(name=argname, scope=scope, autouse=autouse, params=argvalues, ids=ids,
127-
hook=hook, **kwargs)(__param_fixture)
126+
fix = fixture(name=argname, scope=scope, autouse=autouse, params=argvalues, ids=ids,
127+
hook=hook, **kwargs)(__param_fixture)
128128

129129
# Dynamically add fixture to caller's module as explained in https://github.com/pytest-dev/pytest/issues/2424
130130
check_name_available(fixtures_dest, argname, if_name_exists=WARN, caller=param_fixture)
@@ -213,7 +213,7 @@ def _create_params_fixture(fixtures_dest,
213213
if debug:
214214
print("Creating parametrized 'root' fixture %r returning %r" % (root_fixture_name, argvalues))
215215

216-
@fixture_plus(name=root_fixture_name, autouse=autouse, scope=scope, hook=hook, **kwargs)
216+
@fixture(name=root_fixture_name, autouse=autouse, scope=scope, hook=hook, **kwargs)
217217
@pytest.mark.parametrize(argnames, argvalues, ids=ids)
218218
@with_signature("%s(%s)" % (root_fixture_name, argnames))
219219
def _root_fixture(**_kwargs):
@@ -232,7 +232,7 @@ def _create_fixture(_param_idx):
232232
if debug:
233233
print("Creating nonparametrized 'view' fixture %r returning %r[%s]" % (argname, root_fixture_name, _param_idx))
234234

235-
@fixture_plus(name=argname, scope=scope, autouse=autouse, hook=hook, **kwargs)
235+
@fixture(name=argname, scope=scope, autouse=autouse, hook=hook, **kwargs)
236236
@with_signature("%s(%s)" % (argname, root_fixture_name))
237237
def _param_fixture(**_kwargs):
238238
params = _kwargs.pop(root_fixture_name)
@@ -261,7 +261,7 @@ def _param_fixture(**_kwargs):
261261
@pytest.hookimpl(optionalhook=True)
262262
def pytest_fixture_plus(*args,
263263
**kwargs):
264-
warn("`pytest_fixture_plus` is deprecated. Please use the new alias `fixture_plus`. "
264+
warn("`pytest_fixture_plus` and `fixture_plus` are deprecated. Please use the new alias `fixture`. "
265265
"See https://github.com/pytest-dev/pytest/issues/6475", category=DeprecationWarning, stacklevel=2)
266266
if len(args) == 1:
267267
if callable(args[0]):
@@ -272,14 +272,18 @@ def _fixture_plus(f):
272272
return _fixture_plus
273273

274274

275+
fixture_plus = pytest_fixture_plus
276+
"""Deprecated too"""
277+
278+
275279
@function_decorator
276-
def fixture_plus(scope="function", # type: str
277-
autouse=False, # type: bool
278-
name=None, # type: str
279-
unpack_into=None, # type: Iterable[str]
280-
hook=None, # type: Callable[[Callable], Callable]
281-
fixture_func=DECORATED, # noqa
282-
**kwargs):
280+
def fixture(scope="function", # type: str
281+
autouse=False, # type: bool
282+
name=None, # type: str
283+
unpack_into=None, # type: Iterable[str]
284+
hook=None, # type: Callable[[Callable], Callable]
285+
fixture_func=DECORATED, # noqa
286+
**kwargs):
283287
""" decorator to mark a fixture factory function.
284288
285289
Identical to `@pytest.fixture` decorator, except that
@@ -389,7 +393,7 @@ def _decorate_fixture_plus(fixture_func,
389393
else:
390394
if 'params' in kwargs:
391395
raise ValueError(
392-
"With `fixture_plus` you cannot mix usage of the keyword argument `params` and of "
396+
"With `fixture` you cannot mix usage of the keyword argument `params` and of "
393397
"the pytest.mark.parametrize marks")
394398

395399
# (2) create the huge "param" containing all params combined
@@ -403,7 +407,7 @@ def _decorate_fixture_plus(fixture_func,
403407

404408
# check number of parameter names in this parameterset
405409
if len(pmark.param_names) < 1:
406-
raise ValueError("Fixture function '%s' decorated with '@fixture_plus' has an empty parameter "
410+
raise ValueError("Fixture function '%s' decorated with '@fixture' has an empty parameter "
407411
"name in a @pytest.mark.parametrize mark")
408412

409413
# remember the argnames

pytest_cases/fixture_parametrize_plus.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .fixture__creation import check_name_available, CHANGE, WARN
3333
from .fixture_core1_unions import InvalidParamsList, NOT_USED, UnionFixtureAlternative, _make_fixture_union, \
3434
_make_unpack_fixture, UnionIdMakers
35-
from .fixture_core2 import _create_param_fixture, fixture_plus
35+
from .fixture_core2 import _create_param_fixture, fixture
3636

3737

3838
def _fixture_product(fixtures_dest,
@@ -102,8 +102,8 @@ def _new_fixture(request, **all_fixtures):
102102
_new_fixture.__name__ = name
103103

104104
# finally create the fixture per se.
105-
# WARNING we do not use pytest.fixture but fixture_plus so that NOT_USED is discarded
106-
f_decorator = fixture_plus(scope=scope, autouse=autouse, hook=hook, **kwargs)
105+
# WARNING we do not use pytest.fixture but fixture so that NOT_USED is discarded
106+
f_decorator = fixture(scope=scope, autouse=autouse, hook=hook, **kwargs)
107107
fix = f_decorator(_new_fixture)
108108

109109
# Dynamically add fixture to caller's module as explained in https://github.com/pytest-dev/pytest/issues/2424
@@ -123,7 +123,7 @@ def _new_fixture(request, **all_fixtures):
123123

124124
class fixture_ref(object): # noqa
125125
"""
126-
A reference to a fixture, to be used in `@parametrize_plus`.
126+
A reference to a fixture, to be used in `@parametrize`.
127127
You can create it from a fixture name or a fixture object (function).
128128
"""
129129
__slots__ = 'fixture', 'theoretical_size', '_id'
@@ -199,13 +199,16 @@ def __repr__(self):
199199
@pytest.hookimpl(optionalhook=True)
200200
def pytest_parametrize_plus(*args,
201201
**kwargs):
202-
warn("`pytest_parametrize_plus` is deprecated. Please use the new alias `parametrize_plus`. "
202+
warn("`pytest_parametrize_plus` and `parametrize_plus` are deprecated. Please use the new alias `parametrize`. "
203203
"See https://github.com/pytest-dev/pytest/issues/6475", category=DeprecationWarning, stacklevel=2)
204-
return parametrize_plus(*args, **kwargs)
204+
return parametrize(*args, **kwargs)
205+
206+
207+
parametrize_plus = pytest_parametrize_plus
205208

206209

207210
class ParamAlternative(UnionFixtureAlternative):
208-
"""Defines an "alternative", used to parametrize a fixture union in the context of parametrize_plus
211+
"""Defines an "alternative", used to parametrize a fixture union in the context of parametrize
209212
210213
It is similar to a union fixture alternative, except that it also remembers the parameter argnames.
211214
They are used to generate the test id corresponding to this alternative. See `_get_minimal_id` implementations.
@@ -593,17 +596,17 @@ def nostyle(cls,
593596
_IDGEN = object()
594597

595598

596-
def parametrize_plus(argnames=None, # type: str
597-
argvalues=None, # type: Iterable[Any]
598-
indirect=False, # type: bool
599-
ids=None, # type: Union[Callable, Iterable[str]]
600-
idstyle=None, # type: Union[str, Callable]
601-
idgen=_IDGEN, # type: Union[str, Callable]
602-
auto_refs=True, # type: bool
603-
scope=None, # type: str
604-
hook=None, # type: Callable[[Callable], Callable]
605-
debug=False, # type: bool
606-
**args):
599+
def parametrize(argnames=None, # type: str
600+
argvalues=None, # type: Iterable[Any]
601+
indirect=False, # type: bool
602+
ids=None, # type: Union[Callable, Iterable[str]]
603+
idstyle=None, # type: Union[str, Callable]
604+
idgen=_IDGEN, # type: Union[str, Callable]
605+
auto_refs=True, # type: bool
606+
scope=None, # type: str
607+
hook=None, # type: Callable[[Callable], Callable]
608+
debug=False, # type: bool
609+
**args):
607610
"""
608611
Equivalent to `@pytest.mark.parametrize` but also supports
609612
@@ -918,7 +921,7 @@ def parametrize_plus_decorate(test_func, fixtures_dest):
918921
main_fixture_style_template = "%s_%s"
919922
fixture_union_name = main_fixture_style_template % (test_func_name, param_names_str)
920923
fixture_union_name = check_name_available(fixtures_dest, fixture_union_name, if_name_exists=CHANGE,
921-
caller=parametrize_plus)
924+
caller=parametrize)
922925

923926
# Retrieve (if ref) or create (for normal argvalues) the fixtures that we will union
924927
fixture_alternatives = []
@@ -984,7 +987,7 @@ def parametrize_plus_decorate(test_func, fixtures_dest):
984987
_idstyle = idstyle
985988

986989
# note: the function automatically registers it in the module
987-
_make_fixture_union(fixtures_dest, name=fixture_union_name, hook=hook, caller=parametrize_plus,
990+
_make_fixture_union(fixtures_dest, name=fixture_union_name, hook=hook, caller=parametrize,
988991
fix_alternatives=fixture_alternatives, unique_fix_alt_names=fix_alt_names,
989992
idstyle=_idstyle, scope=scope)
990993

0 commit comments

Comments
 (0)