Skip to content

Commit 0fbc534

Browse files
committed
fix buggy test__check_pandas_assert_kwargs
don't use monkeypatch and mocker in the same test function. pytest-dev/pytest-mock#289
1 parent 05e9d95 commit 0fbc534

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

pvlib/tests/test_conftest.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,17 @@ def test_use_fixture_with_decorator(some_data):
5252
'assert_frame_equal'])
5353
@pytest.mark.parametrize('pd_version', ['1.0.0', '1.1.0'])
5454
@pytest.mark.parametrize('check_less_precise', [True, False])
55-
def test__check_pandas_assert_kwargs(mocker, monkeypatch,
56-
function_name, pd_version,
55+
def test__check_pandas_assert_kwargs(mocker, function_name, pd_version,
5756
check_less_precise):
5857
# test that conftest._check_pandas_assert_kwargs returns appropriate
5958
# kwargs for the assert_x_equal functions
6059

61-
# patch the pandas assert; not interested in actually calling them:
62-
def patched_assert(*args, **kwargs):
63-
pass
64-
65-
monkeypatch.setattr(pandas.testing, function_name, patched_assert)
66-
# then attach a spy to it so we can see what args it is called with:
67-
mocked_function = mocker.spy(pandas.testing, function_name)
60+
# patch the pandas assert; not interested in actually calling them,
61+
# plus we want to spy on how they get called.
62+
spy = mocker.patch('pandas.testing.' + function_name)
6863
# patch pd.__version__ to exercise the two branches in
6964
# conftest._check_pandas_assert_kwargs
70-
monkeypatch.setattr(pandas, '__version__', pd_version)
65+
mocker.patch('pandas.__version__', new=pd_version)
7166

7267
# finally, run the function and check what args got passed to pandas:
7368
assert_function = getattr(conftest, function_name)
@@ -79,4 +74,4 @@ def patched_assert(*args, **kwargs):
7974
else:
8075
expected_kwargs = {'check_less_precise': check_less_precise}
8176

82-
mocked_function.assert_called_with(*args, **expected_kwargs)
77+
spy.assert_called_once_with(*args, **expected_kwargs)

0 commit comments

Comments
 (0)