Skip to content

Commit

Permalink
fix buggy test__check_pandas_assert_kwargs
Browse files Browse the repository at this point in the history
don't use monkeypatch and mocker in the same test function.  pytest-dev/pytest-mock#289
  • Loading branch information
kandersolar committed Apr 22, 2022
1 parent 05e9d95 commit 0fbc534
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions pvlib/tests/test_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,17 @@ def test_use_fixture_with_decorator(some_data):
'assert_frame_equal'])
@pytest.mark.parametrize('pd_version', ['1.0.0', '1.1.0'])
@pytest.mark.parametrize('check_less_precise', [True, False])
def test__check_pandas_assert_kwargs(mocker, monkeypatch,
function_name, pd_version,
def test__check_pandas_assert_kwargs(mocker, function_name, pd_version,
check_less_precise):
# test that conftest._check_pandas_assert_kwargs returns appropriate
# kwargs for the assert_x_equal functions

# patch the pandas assert; not interested in actually calling them:
def patched_assert(*args, **kwargs):
pass

monkeypatch.setattr(pandas.testing, function_name, patched_assert)
# then attach a spy to it so we can see what args it is called with:
mocked_function = mocker.spy(pandas.testing, function_name)
# patch the pandas assert; not interested in actually calling them,
# plus we want to spy on how they get called.
spy = mocker.patch('pandas.testing.' + function_name)
# patch pd.__version__ to exercise the two branches in
# conftest._check_pandas_assert_kwargs
monkeypatch.setattr(pandas, '__version__', pd_version)
mocker.patch('pandas.__version__', new=pd_version)

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

mocked_function.assert_called_with(*args, **expected_kwargs)
spy.assert_called_once_with(*args, **expected_kwargs)

0 comments on commit 0fbc534

Please sign in to comment.