Skip to content

TST: Test patching over fake instead of real method in accessor test #55584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions pandas/tests/test_register_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,13 @@ def test_accessor_works():


def test_overwrite_warns():
# Need to restore mean
mean = pd.Series.mean
try:
with tm.assert_produces_warning(UserWarning) as w:
pd.api.extensions.register_series_accessor("mean")(MyAccessor)
match = r".*MyAccessor.*fake.*Series.*"
with tm.assert_produces_warning(UserWarning, match=match):
with ensure_removed(pd.Series, "fake"):
setattr(pd.Series, "fake", 123)
pd.api.extensions.register_series_accessor("fake")(MyAccessor)
s = pd.Series([1, 2])
assert s.mean.prop == "item"
msg = str(w[0].message)
assert "mean" in msg
assert "MyAccessor" in msg
assert "Series" in msg
finally:
pd.Series.mean = mean
assert s.fake.prop == "item"


def test_raises_attribute_error():
Expand Down