-
Notifications
You must be signed in to change notification settings - Fork 44
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
Enhance assertion output for assert_all_called
#224
Conversation
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #224 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 2757 2755 -2
Branches 417 417
=========================================
- Hits 2757 2755 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a most welcome enhancement @sileht !
respx/router.py
Outdated
raise AllCalledAssertionError("RESPX: some routes were not called!") | ||
not_called_routes = {str(route) for route in self.routes if not route.called} | ||
if not_called_routes: | ||
formatted_not_called_routes = "* " + "\n* ".join(not_called_routes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can make use of regular failed assertion output, instead of manual rendering 🤔
I'm thinking that this would give us the desired output:
assert not_called_routes == set(), "RESPX: some routes were not called!"
Yeah, this looks even nicer. Here is a pytest example:
I have to use a list instead of a set as the Route object is not hashable. |
Another example, if we also list called routes with:
Tell me which one you prefer and I will update the pull request. |
👍
I'd say the first implementation aligns better with the assertion, i.e. all called == no remaining non-called A third alternative that might give roughly the same output would be ... assert len(non_called_routes) == 0 |
So it's ready 😀 |
Almost .. We should probably drop the |
Once |
When AllCalledAssertionError is raised its hard to guess which route got called and which routes didn't get called. This change aims to provide more details by listing not called routes and by leveraging the __repr__ of route object.
assert_all_called
Thanks @sileht |
When AllCalledAssertionError is raised its hard to guess which route got
called and which routes didn't get called.
This change aims to provide more details by listing not called routes
and by leveraging the repr of route object.