|
4 | 4 | # License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE> |
5 | 5 | from collections import OrderedDict, namedtuple |
6 | 6 | from copy import copy |
7 | | -from distutils.version import LooseVersion |
8 | 7 | from functools import partial |
9 | 8 | from warnings import warn |
10 | 9 |
|
|
34 | 33 |
|
35 | 34 | from .fixture_core1_unions import NOT_USED, is_fixture_union_params, UnionFixtureAlternative |
36 | 35 |
|
| 36 | +if PYTEST54_OR_GREATER: |
| 37 | + # we will need to clean the empty ids explicitly in the plugin :'( |
| 38 | + from .fixture_parametrize_plus import remove_empty_ids |
37 | 39 |
|
38 | 40 | _DEBUG = False |
39 | 41 |
|
@@ -729,19 +731,22 @@ def __str__(self): |
729 | 731 | def parametrize(metafunc, argnames, argvalues, indirect=False, ids=None, scope=None, **kwargs): |
730 | 732 | """ |
731 | 733 | This alternate implementation of metafunc.parametrize creates a list of calls that is not just the cartesian |
732 | | - product of all parameters (like the pytest behaviour). |
733 | | -
|
734 | | - Instead, it offers an alternate list of calls takinginto account all union fixtures. |
| 734 | + product of all parameters (like the pytest behaviour). Instead, it offers an alternate list of calls taking into |
| 735 | + account all "union" fixtures. |
735 | 736 |
|
736 | 737 | For this, it replaces the `metafunc._calls` attribute with a `CallsReactor` instance, and feeds it with all |
737 | | - parameters and parametrized fixtures independently (not doing any cross-product). |
738 | | -
|
739 | | - The resulting `CallsReactor` instance is then able to dynamically behave like the correct list of calls, |
740 | | - lazy-creating that list when it is used. |
| 738 | + parameters and parametrized fixtures independently (not doing any cross-product during this call). The resulting |
| 739 | + `CallsReactor` instance is then able to dynamically behave like the correct list of calls, lazy-creating that list |
| 740 | + when it is used. |
741 | 741 | """ |
742 | 742 | if not isinstance(metafunc.fixturenames, SuperClosure): |
743 | 743 | # legacy method |
744 | 744 | metafunc.__class__.parametrize(metafunc, argnames, argvalues, indirect=indirect, ids=ids, scope=scope, **kwargs) |
| 745 | + |
| 746 | + # clean EMPTY_ID : since they are never set by us in a normal parametrize, no need to do this here. |
| 747 | + # if PYTEST54_OR_GREATER: |
| 748 | + # for callspec in metafunc._calls: |
| 749 | + # remove_empty_ids(callspec) |
745 | 750 | else: |
746 | 751 | # get or create our special container object |
747 | 752 | if not isinstance(metafunc._calls, CallsReactor): # noqa |
@@ -864,6 +869,11 @@ def create_call_list_from_pending_parametrizations(self): |
864 | 869 | c.id, c.funcargs, c.params) |
865 | 870 | for c in calls]) + "\n") |
866 | 871 |
|
| 872 | + # clean EMPTY_ID set by @parametrize when there is at least a MultiParamsAlternative |
| 873 | + if PYTEST54_OR_GREATER: |
| 874 | + for callspec in calls: |
| 875 | + remove_empty_ids(callspec) |
| 876 | + |
867 | 877 | # save the list and put back self as the _calls facade |
868 | 878 | self._call_list = calls |
869 | 879 | self.metafunc._calls = self |
@@ -1107,12 +1117,6 @@ def _parametrize_calls(metafunc, init_calls, argnames, argvalues, discard_id=Fal |
1107 | 1117 | for callspec in new_calls: |
1108 | 1118 | callspec._idlist.pop(-1) # noqa |
1109 | 1119 |
|
1110 | | - # Fix in pytest 5.4.0 or greater, empty ids are not filtered out correctly anymore |
1111 | | - if PYTEST54_OR_GREATER and len(new_calls) > 0: |
1112 | | - # old_id = type(new_calls[0]).id # https://github.com/pytest-dev/pytest/blob/5.4.0/src/_pytest/python.py#L798 |
1113 | | - if type(new_calls[0]).id is not id: |
1114 | | - type(new_calls[0]).id = id |
1115 | | - |
1116 | 1120 | # restore the metafunc and return the new calls |
1117 | 1121 | metafunc._calls = bak |
1118 | 1122 | return new_calls |
|
0 commit comments