Skip to content

Commit

Permalink
TST: Test patching over fake instead of real method in accessor test (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored Oct 19, 2023
1 parent ca39324 commit c31c6ba
Showing 1 changed file with 6 additions and 12 deletions.
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

0 comments on commit c31c6ba

Please sign in to comment.