Skip to content

Commit 62e7e2b

Browse files
committed
fix: Fix empty parameter set error by adding non-None config to MiniMetafunc
1 parent 6ed4c3e commit 62e7e2b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pytest_cases/common_pytest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE>
55
from __future__ import division
66

7+
import sys
8+
79
from makefun import add_signature_parameters, wraps
810

911
try: # python 3.3+
@@ -537,8 +539,6 @@ def mini_idvalset(argnames, argvalues, idx):
537539
try:
538540
from _pytest.compat import getfuncargnames # noqa
539541
except ImportError:
540-
import sys
541-
542542
def num_mock_patch_args(function):
543543
""" return number of arguments used up by mock arguments (if any) """
544544
patchings = getattr(function, "patchings", None)
@@ -588,7 +588,9 @@ def __init__(self, nodeid):
588588
class MiniMetafunc(Metafunc):
589589
# noinspection PyMissingConstructor
590590
def __init__(self, func):
591-
self.config = None
591+
from .plugin import PYTEST_CONFIG # late import to ensure config has been loaded by now
592+
593+
self.config = PYTEST_CONFIG
592594
self.function = func
593595
self.definition = MiniFuncDef(func.__name__)
594596
self._calls = []

pytest_cases/plugin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,14 +1290,21 @@ def pytest_addoption(parser):
12901290
)
12911291

12921292

1293+
# will be loaded when the pytest_configure hook below is called
1294+
PYTEST_CONFIG = None # type: _pytest.config.Config
1295+
1296+
12931297
# @hookspec(historic=True)
12941298
def pytest_configure(config):
1299+
global PYTEST_CONFIG
12951300
# validate the config
12961301
allowed_values = ('normal', 'skip')
12971302
reordering_choice = config.getoption(_OPTION_NAME)
12981303
if reordering_choice not in allowed_values:
12991304
raise ValueError("[pytest-cases] Wrong --%s option: %s. Allowed values: %s"
13001305
"" % (_OPTION_NAME, reordering_choice, allowed_values))
1306+
# store the received config object for future use; see #165 & #166
1307+
PYTEST_CONFIG = config
13011308

13021309

13031310
@pytest.hookimpl(tryfirst=True, hookwrapper=True)

0 commit comments

Comments
 (0)