-
-
Notifications
You must be signed in to change notification settings - Fork 260
Pytest complaining on CI about "mocker in a context not supported" #678
Copy link
Copy link
Closed
Description
For the tests tests/test_incremental.py::test_replace_scoring[SGDClassifier-fit_kwargs0-accuracy] and tests/test_incremental.py::test_replace_scoring[SGDRegressor-fit_kwargs1-r2].
Here's the error produced at the end:
ValueError: Using mocker in a with context is not supported. https://github.com/pytest-dev/pytest-mock#note-about-usage-as-context-manager
The link is https://github.com/pytest-dev/pytest-mock#note-about-usage-as-context-manager. The full traceback:
2020-06-05T01:54:58.5879474Z ___________ test_replace_scoring[SGDClassifier-fit_kwargs0-accuracy] ___________
2020-06-05T01:54:58.5879901Z
2020-06-05T01:54:58.5880365Z estimator = <class 'sklearn.linear_model._stochastic_gradient.SGDClassifier'>
2020-06-05T01:54:58.5880922Z fit_kwargs = {'classes': [0, 1]}, scoring = 'accuracy'
2020-06-05T01:54:58.5881424Z xy_classification = (dask.array<normal, shape=(100, 20), dtype=float64, chunksize=(10, 20), chunktype=numpy.ndarray>, dask.array<astype, shape=(100,), dtype=int64, chunksize=(10,), chunktype=numpy.ndarray>)
2020-06-05T01:54:58.5881951Z mocker = <pytest_mock.plugin.MockFixture object at 0x7fce2d98b400>
2020-06-05T01:54:58.5882178Z
2020-06-05T01:54:58.5882385Z @pytest.mark.parametrize(
2020-06-05T01:54:58.5882626Z "estimator, fit_kwargs, scoring",
2020-06-05T01:54:58.5882967Z [(SGDClassifier, {"classes": [0, 1]}, "accuracy"), (SGDRegressor, {}, "r2")],
2020-06-05T01:54:58.5883248Z )
2020-06-05T01:54:58.5883565Z def test_replace_scoring(estimator, fit_kwargs, scoring, xy_classification, mocker):
2020-06-05T01:54:58.5883906Z X, y = xy_classification
2020-06-05T01:54:58.5884384Z inc = Incremental(estimator(max_iter=1000, random_state=0, tol=1e-3))
2020-06-05T01:54:58.5884734Z inc.fit(X, y, **fit_kwargs)
2020-06-05T01:54:58.5884942Z
2020-06-05T01:54:58.5885200Z patch = mocker.patch.object(dask_ml.wrappers, "get_scorer")
2020-06-05T01:54:58.5885470Z > with patch:
2020-06-05T01:54:58.5885645Z
2020-06-05T01:54:58.5885869Z tests/test_incremental.py:183:
2020-06-05T01:54:58.5886162Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2020-06-05T01:54:58.5886736Z /usr/share/miniconda/envs/dask-ml-test/lib/python3.6/unittest/mock.py:939: in __call__
2020-06-05T01:54:58.5887095Z return _mock_self._mock_call(*args, **kwargs)
2020-06-05T01:54:58.5887425Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2020-06-05T01:54:58.5887678Z
2020-06-05T01:54:58.5888096Z _mock_self = <MagicMock name='get_scorer.__enter__' id='140522247884696'>
2020-06-05T01:54:58.5888427Z args = (), kwargs = {}
2020-06-05T01:54:58.5889063Z self = <MagicMock name='get_scorer.__enter__' id='140522247884696'>
2020-06-05T01:54:58.5889475Z _call = call(), seen = {94764811168560}, do_method_calls = False
2020-06-05T01:54:58.5890034Z method_call_name = '__enter__', mock_call_name = '__enter__', is_a_call = False
2020-06-05T01:54:58.5890409Z _new_parent = None, this_mock_call = call.__enter__()
2020-06-05T01:54:58.5890622Z
2020-06-05T01:54:58.5890849Z def _mock_call(_mock_self, *args, **kwargs):
2020-06-05T01:54:58.5891129Z self = _mock_self
2020-06-05T01:54:58.5891347Z self.called = True
2020-06-05T01:54:58.5891586Z self.call_count += 1
2020-06-05T01:54:58.5891781Z
2020-06-05T01:54:58.5891971Z # handle call_args
2020-06-05T01:54:58.5892233Z _call = _Call((args, kwargs), two=True)
2020-06-05T01:54:58.5892490Z self.call_args = _call
2020-06-05T01:54:58.5892747Z self.call_args_list.append(_call)
2020-06-05T01:54:58.5892963Z
2020-06-05T01:54:58.5893166Z seen = set()
2020-06-05T01:54:58.5893354Z
2020-06-05T01:54:58.5893572Z # initial stuff for method_calls:
2020-06-05T01:54:58.5893871Z do_method_calls = self._mock_parent is not None
2020-06-05T01:54:58.5894145Z method_call_name = self._mock_name
2020-06-05T01:54:58.5894378Z
2020-06-05T01:54:58.5894593Z # initial stuff for mock_calls:
2020-06-05T01:54:58.5894873Z mock_call_name = self._mock_new_name
2020-06-05T01:54:58.5895308Z is_a_call = mock_call_name == '()'
2020-06-05T01:54:58.5895777Z self.mock_calls.append(_Call(('', args, kwargs)))
2020-06-05T01:54:58.5896056Z
2020-06-05T01:54:58.5896279Z # follow up the chain of mocks:
2020-06-05T01:54:58.5896560Z _new_parent = self._mock_new_parent
2020-06-05T01:54:58.5896827Z while _new_parent is not None:
2020-06-05T01:54:58.5897154Z
2020-06-05T01:54:58.5897386Z # handle method_calls:
2020-06-05T01:54:58.5897703Z if do_method_calls:
2020-06-05T01:54:58.5898033Z _new_parent.method_calls.append(_Call((method_call_name, args, kwargs)))
2020-06-05T01:54:58.5898388Z do_method_calls = _new_parent._mock_parent is not None
2020-06-05T01:54:58.5898702Z if do_method_calls:
2020-06-05T01:54:58.5899229Z method_call_name = _new_parent._mock_name + '.' + method_call_name
2020-06-05T01:54:58.5901464Z
2020-06-05T01:54:58.5901774Z # handle mock_calls:
2020-06-05T01:54:58.5902063Z this_mock_call = _Call((mock_call_name, args, kwargs))
2020-06-05T01:54:58.5902391Z _new_parent.mock_calls.append(this_mock_call)
2020-06-05T01:54:58.5902624Z
2020-06-05T01:54:58.5902863Z if _new_parent._mock_new_name:
2020-06-05T01:54:58.5903130Z if is_a_call:
2020-06-05T01:54:58.5903635Z dot = ''
2020-06-05T01:54:58.5903906Z else:
2020-06-05T01:54:58.5904293Z dot = '.'
2020-06-05T01:54:58.5904780Z is_a_call = _new_parent._mock_new_name == '()'
2020-06-05T01:54:58.5905139Z mock_call_name = _new_parent._mock_new_name + dot + mock_call_name
2020-06-05T01:54:58.5905423Z
2020-06-05T01:54:58.5905644Z # follow the parental chain:
2020-06-05T01:54:58.5905937Z _new_parent = _new_parent._mock_new_parent
2020-06-05T01:54:58.5906164Z
2020-06-05T01:54:58.5906562Z # check we're not in an infinite loop:
2020-06-05T01:54:58.5906925Z # ( use ids here so as not to call __hash__ on the mocks)
2020-06-05T01:54:58.5907222Z _new_parent_id = id(_new_parent)
2020-06-05T01:54:58.5907510Z if _new_parent_id in seen:
2020-06-05T01:54:58.5907750Z break
2020-06-05T01:54:58.5907990Z seen.add(_new_parent_id)
2020-06-05T01:54:58.5908203Z
2020-06-05T01:54:58.5908399Z effect = self.side_effect
2020-06-05T01:54:58.5908669Z if effect is not None:
2020-06-05T01:54:58.5908929Z if _is_exception(effect):
2020-06-05T01:54:58.5909198Z > raise effect
2020-06-05T01:54:58.5909837Z E ValueError: Using mocker in a with context is not supported. https://github.com/pytest-dev/pytest-mock#note-about-usage-as-context-manager
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels