Skip to content

Commit

Permalink
Fix CallList assertion error message (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Nov 8, 2021
1 parent 97a9e28 commit 97eb9ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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

0 comments on commit 97eb9ae

Please sign in to comment.