-
Notifications
You must be signed in to change notification settings - Fork 137
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
feat: improve mismatch error #815
Conversation
@individual-it This hopefully goes some way to address the visibility of the mismatches when a Pact test fails. I'm still implementing the tests for this, but the actual implementation should mostly be there (pending confirmation from the tests I'm writing) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #815 +/- ##
======================================
Coverage 78% 78%
======================================
Files 29 30 +1
Lines 3060 3366 +306
======================================
+ Hits 2395 2636 +241
- Misses 665 730 +65
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Thank you!
I has no time yet to try that with provider side tests, but with consumer side tests I found some issues in the from_dict
function
Returns: | ||
A new Mismatch object. | ||
""" | ||
if mismatch_type := data.pop("type"): |
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.
when running into this error with consumer tests, data
is a list not a dict
e.g.
[{'method': 'GET', 'path': '/users/123', 'request': {'body': '', 'headers': {'accept': '*/*', 'accept-encoding': 'gzip, deflate, zstd', 'connection': 'keep-alive', 'host': 'localhost:38499', 'user-agent': 'python-requests/2.32.3'}, 'method': 'GET', 'path': '/users/123'}, 'type': 'request-not-found'}, {'method': 'GET', 'path': '/user/123', 'request': {'method': 'GET', 'path': '/user/123'}, 'type': 'missing-request'}]
so this ends up in a TypeError: 'str' object cannot be interpreted as an integer
if mismatch_type == "BodyMismatch": | ||
return BodyMismatch(**data) | ||
if mismatch_type == "MetadataMismatch": | ||
return MetadataMismatch(**data) |
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.
I could not provoke any of those types.
All types I could provoke so far (in consumer tests) are Kebab Case
request-not-found
or missing-request
so they will always end up as GenericMismatch
. Is that intended?
Yeah I'm still working on the breaking changes introduced for tests that inspect errors. It's also catching a number of other 'mismatches' such as the request not found you mentioned. |
d5ca690
to
80fd458
Compare
This adds a new `Mismatch` class, with specific different kinds of mismatches being subclasses of this class. BREAKING CHANGE: The `srv.mismatches` is changed from a `list[dict[str, Any]]` to a `list[Mismatch]`. Signed-off-by: JP-Ellis <josh@jpellis.me>
80fd458
to
caf5efd
Compare
Signed-off-by: JP-Ellis <josh@jpellis.me>
With the `Matcher` accepting a generic typevar, there were a few instances where the typevar was missing. Signed-off-by: JP-Ellis <josh@jpellis.me>
caf5efd
to
d86e54b
Compare
📝 Summary
Adds a
Mismatch
class and a number of subclasses.This is done to facilitate the error handling, and error displays.
🚨 Breaking Changes
MismatchesError
is now different. It was adict[str, Any]
and is now aMismatch
sub-class.🔥 Motivation
Improve error messages, as the old error messages were clearly not appropriate.
🔨 Test Plan
At time of writing, yet to be done.
🔗 Related issues/PRs
Mismatch
class #644