Skip to content
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

Fix CallList assertion error message #178

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions respx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class Call(NamedTuple):


class CallList(list, mock.NonCallableMock):
def __init__(self, *args, name="respx", **kwargs):
super().__init__(*args, **kwargs)
mock.NonCallableMock.__init__(self, name=name)

@property
def called(self) -> bool: # type: ignore
return bool(self)
Expand Down Expand Up @@ -106,7 +110,7 @@ def __init__(
self._pass_through: bool = False
self._name: Optional[str] = None
self._snapshots: List[Tuple] = []
self.calls = CallList()
self.calls = CallList(name=self)
self.snapshot()

def __eq__(self, other: object) -> bool:
Expand Down Expand Up @@ -196,7 +200,7 @@ def snapshot(self) -> None:
self._return_value,
side_effect,
self._pass_through,
CallList(self.calls),
CallList(self.calls, name=self),
),
)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ def test_rollback():
assert route.call_count == 1
assert route.return_value.status_code == 418

router.snapshot() # 3. directly rollback, should be identical
router.rollback()
assert len(router.routes) == 2
assert router.calls.call_count == 2
assert route.call_count == 1
assert route.return_value.status_code == 418

router.patch("https://foo.bar/")
assert len(router.routes) == 3

Expand Down
6 changes: 6 additions & 0 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ async def backend_test(backend):
assert respx.calls.call_count == len(respx.calls)
assert respx.calls.call_count == 0

with pytest.raises(AssertionError, match="Expected 'respx' to have been called"):
respx.calls.assert_called_once()

with pytest.raises(AssertionError, match="Expected '<Route name='get_foobar'"):
foobar1.calls.assert_called_once()

async with httpx.AsyncClient() as client:
get_response = await client.get(url)
del_response = await client.delete(url)
Expand Down