-
Notifications
You must be signed in to change notification settings - Fork 224
Test improvements #1219
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
Merged
ryneeverett
merged 11 commits into
GothenburgBitFactory:develop
from
Lotram:test-improvements
Jun 23, 2026
Merged
Test improvements #1219
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
856dc37
Change TestTemplates inheritance to keep only needed parent class
Lotram b404747
Improve test isolation
Lotram ca5379c
move service tests to dedicated folder to mirror the source code arch…
Lotram d393f3b
Remove deprecated response parameter
Lotram e02d168
AbstractServiceTest renamed to ServiceIssueTest and inherit from Ser…
Lotram 2e4e0c4
remove repeated maxDiff attribute in service tests
Lotram 1f5eb87
fix: several test improvements
Lotram bfdba27
fix validation when no service as a "service" key
Lotram 706af4b
remove useless comment in tests
Lotram b0c73f6
remove unnecessary test setup
Lotram e238f93
Add comment about _MissingServiceDiscriminator
Lotram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This does seem to improve the outcome as shown in the tests, but can you explain it? I take it that the problem had something to do with the early
returnwithout the descriminatorField? But what is the fundamental difference between_MissingServiceDiscriminatorandServiceConfig?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.
It's related to
_format_service_errorerror handling. When going through theServiceConfigblock,loc = (0, "service"), type = "missing"whereas the block we want in_format_service_errorisif len(loc) == 1loc = (0, "username") type = "extra_forbidden"error, becauseServiceConfigdoes not know the service-specific fields. When using a discriminator field, if the discriminator raises an error, pydantic stop there and does not go through other errors.This can also be modified in the error handling function, though I thought it was simpler to simply have an empty discriminator class
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 think I basically follow that explanation, but how does
_MissingServiceDiscriminatoravoid those issues?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.
We need to have discriminated union to be as close as possible to the general case (when we have valid configs), for the reasons above.
so I guess your question is: why don't we fallback on
service_config_classes = ServiceConfiginstead ofservice_config_classes = _MissingServiceDiscriminator, when there is no valid service config ?Simply because a discriminator requires the field (
servicehere), to be aLiteral, not astrTo validate models based on that information, you can set a common field on each model of the union (pet_type in the example below), typed as accepting one or multiple literal values.
The doc says:
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, I get it now! I opened Lotram#2 as a proposed alternative which i find more readable and possibly more correct since
servicecan't actually be an arbitrarystr.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 can see a problem with your implementation:
Literal["__bugwarrior_service_placeholder__"](type from the base class) is not compatible withLiteral["github"], so there is a theoretical typing problem.I agree
servicecan't be an arbitrary string, it should be the Union of all declared service types, but since this registration is dynamic (and we don't want to register unused services), we have a problem. So IMO,stris "truer" thanLiteral["__bugwarrior_service_placeholder__"]Here is a minimal example to reproduce:
Incompatible types in assignment (expression has type "Literal['github']", base class "Config" defined the type as "Literal['_error_']"))Note that pyright would still complain with the regular
strinstead ofLiteral, because "Variable is mutable so its type is invariant" (and it still complains when usingfrozen=Trueand `ClassVar), pyright complains a lotSo, as a conclusion, I'm ok with your implementation if you prefer it, for simplicity sake, but I think it's just a tiny bit more wrong
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.
No, let's stick with the more correct implementation. My only ask would be, please add at least a sentence of explanation to the
_MissingServiceDiscriminatordocstring about how it's essential purpose is to make theservicefield aLiteralso it will work as a discriminator. I think using theServiceConfigbase class as a fallback here is the intuitive implementation -- after all it's what you did initially -- so this is a natural place for anyone to wonder why this class is necessary.