Don't try to mock context manager; use a simple class instead#39
Merged
Don't try to mock context manager; use a simple class instead#39
Conversation
7d5d75e to
b91a059
Compare
brandur
commented
Jan 25, 2025
.github/workflows/ci.yaml
Outdated
|
|
||
| - name: river migrate-up | ||
| run: river migrate-up --database-url "$TEST_DATABASE_URL" | ||
| run: river migrate-up --database-url "$DATABASE_URL" --max-steps 5 # temporarily include max steps so tests can pass with unique fixes |
Contributor
Author
There was a problem hiding this comment.
Change needed for tests to pass, but should be reverted in #38.
This one's related to #38. It turns out that while trying to mock a context manager kind of works, it will do the wrong thing in edge cases like when an exception is thrown from inside a `with` block, silently swallowing it and causing a return that's completely wrong. There may be some way to fix the mock to make it do the right thing, but instead of getting fancier with these mocks that are already awful, instead repair the problem by defining a plain class that implements context manager and just use that.
b91a059 to
a01790c
Compare
4 tasks
brandur
commented
Jan 25, 2025
|
|
||
| - name: river migrate-up | ||
| run: river migrate-up --database-url "$TEST_DATABASE_URL" | ||
| run: river migrate-up --database-url "$TEST_DATABASE_URL" --max-steps 5 # temporarily include max steps so tests can pass with unique fixes |
Contributor
Author
There was a problem hiding this comment.
Change needed for tests to pass, but should be reverted in #38.
bgentry
approved these changes
Jan 25, 2025
Contributor
bgentry
left a comment
There was a problem hiding this comment.
That explains what I was running into, thanks!
Contributor
Author
|
thx. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This one's related to #38. It turns out that while trying to mock a
context manager kind of works, it will do the wrong thing in edge cases
like when an exception is thrown from inside a
withblock, silentlyswallowing it and causing a return that's completely wrong.
There may be some way to fix the mock to make it do the right thing, but
instead of getting fancier with these mocks that are already awful,
instead repair the problem by defining a plain class that implements
context manager and just use that.