Skip to content

Commit 212e723

Browse files
tobixenclaude
andcommitted
Fix test pollution: use patch.object instead of direct class mutation
TestAsyncCalendarAddObject was assigning AsyncMock directly onto AsyncEvent._async_create at class level. Since AsyncEvent is an alias for Event, this left the mock in place for all subsequent tests, breaking test_async_integration.py. Replace with patch.object() context manager so the mock is restored after each test. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c0f06d8 commit 212e723

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

tests/test_async_davclient.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -843,24 +843,22 @@ async def test_add_event_returns_coroutine_with_async_client(self) -> None:
843843
clients, so add_object() must await it instead of doing o.url on the
844844
coroutine object.
845845
"""
846+
import inspect
847+
846848
from caldav.aio import AsyncEvent
847849
from caldav.collection import Calendar
848850

849851
client = AsyncDAVClient(url="https://caldav.example.com/dav/")
850-
# Mock _async_create so no real HTTP happens
851-
AsyncEvent._async_create = AsyncMock()
852-
853852
calendar = Calendar(client=client, url="https://caldav.example.com/dav/calendars/test/")
854853

855-
result = calendar.add_event(self.SIMPLE_EVENT)
856-
# With an async client, add_event must return a coroutine
857-
import inspect
858-
859-
assert inspect.isawaitable(result), (
860-
"add_event() should return a coroutine when using AsyncDAVClient, "
861-
"got %r instead" % result
862-
)
863-
event = await result
854+
with patch.object(AsyncEvent, "_async_create", new_callable=AsyncMock):
855+
result = calendar.add_event(self.SIMPLE_EVENT)
856+
# With an async client, add_event must return a coroutine
857+
assert inspect.isawaitable(result), (
858+
"add_event() should return a coroutine when using AsyncDAVClient, "
859+
"got %r instead" % result
860+
)
861+
event = await result
864862
assert isinstance(event, AsyncEvent)
865863

866864
@pytest.mark.asyncio
@@ -870,10 +868,10 @@ async def test_add_event_result_has_url(self) -> None:
870868
from caldav.collection import Calendar
871869

872870
client = AsyncDAVClient(url="https://caldav.example.com/dav/")
873-
AsyncEvent._async_create = AsyncMock()
874-
875871
calendar = Calendar(client=client, url="https://caldav.example.com/dav/calendars/test/")
876-
event = await calendar.add_event(self.SIMPLE_EVENT)
872+
873+
with patch.object(AsyncEvent, "_async_create", new_callable=AsyncMock):
874+
event = await calendar.add_event(self.SIMPLE_EVENT)
877875
# Should have a URL set (or None, but not crash)
878876
_ = event.url # must not raise AttributeError
879877

0 commit comments

Comments
 (0)