From 62e7e2bf6fc15edb94694a5f33ec2ba3e50a206a Mon Sep 17 00:00:00 2001 From: Paolo Lammens Date: Sun, 13 Dec 2020 23:57:01 +0100 Subject: [PATCH 1/2] fix: Fix empty parameter set error by adding non-None config to MiniMetafunc --- pytest_cases/common_pytest.py | 8 +++++--- pytest_cases/plugin.py | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pytest_cases/common_pytest.py b/pytest_cases/common_pytest.py index 3a57deec..c7539ea2 100644 --- a/pytest_cases/common_pytest.py +++ b/pytest_cases/common_pytest.py @@ -4,6 +4,8 @@ # License: 3-clause BSD, from __future__ import division +import sys + from makefun import add_signature_parameters, wraps try: # python 3.3+ @@ -537,8 +539,6 @@ def mini_idvalset(argnames, argvalues, idx): try: from _pytest.compat import getfuncargnames # noqa except ImportError: - import sys - def num_mock_patch_args(function): """ return number of arguments used up by mock arguments (if any) """ patchings = getattr(function, "patchings", None) @@ -588,7 +588,9 @@ def __init__(self, nodeid): class MiniMetafunc(Metafunc): # noinspection PyMissingConstructor def __init__(self, func): - self.config = None + from .plugin import PYTEST_CONFIG # late import to ensure config has been loaded by now + + self.config = PYTEST_CONFIG self.function = func self.definition = MiniFuncDef(func.__name__) self._calls = [] diff --git a/pytest_cases/plugin.py b/pytest_cases/plugin.py index 4d1c795f..979c29b8 100644 --- a/pytest_cases/plugin.py +++ b/pytest_cases/plugin.py @@ -1290,14 +1290,21 @@ def pytest_addoption(parser): ) +# will be loaded when the pytest_configure hook below is called +PYTEST_CONFIG = None # type: _pytest.config.Config + + # @hookspec(historic=True) def pytest_configure(config): + global PYTEST_CONFIG # validate the config allowed_values = ('normal', 'skip') reordering_choice = config.getoption(_OPTION_NAME) if reordering_choice not in allowed_values: raise ValueError("[pytest-cases] Wrong --%s option: %s. Allowed values: %s" "" % (_OPTION_NAME, reordering_choice, allowed_values)) + # store the received config object for future use; see #165 & #166 + PYTEST_CONFIG = config @pytest.hookimpl(tryfirst=True, hookwrapper=True) From 75c3a93fd4bdddfd22fbd8a3170fd30c99572f0d Mon Sep 17 00:00:00 2001 From: Paolo Lammens Date: Sun, 13 Dec 2020 23:59:41 +0100 Subject: [PATCH 2/2] tests: Test empty parameter set --- pytest_cases/tests/cases/issues/test_issue_165.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 pytest_cases/tests/cases/issues/test_issue_165.py diff --git a/pytest_cases/tests/cases/issues/test_issue_165.py b/pytest_cases/tests/cases/issues/test_issue_165.py new file mode 100644 index 00000000..2d37b714 --- /dev/null +++ b/pytest_cases/tests/cases/issues/test_issue_165.py @@ -0,0 +1,11 @@ +import pytest_cases + + +@pytest_cases.parametrize(x=[]) +def case_empty(x): + return x # pragma: no cover + + +@pytest_cases.parametrize_with_cases("x", case_empty) +def test_empty_parameter_set(x): + assert False # pragma: no cover