Synchronous setup and teardown for @value decorator.
See original GitHub issueValue decorator should handle generators.
This is very similar to the contextlib.contextmanager.
class Container(Injector):
app = App
@value
def db_connection(pool):
connection = pool.aquire()
yield connection
connection.release()
with Container as initialized:
initialized.app.process()
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Set Up and Tear Down State in Your Tests - Apple Developer
async throws first, then setUpWithError() , then setUp() . Use these methods to prepare state that you need for each test method. XCTest...
Read more >How do I correctly setup and teardown for my pytest class with ...
According to Fixture finalization / executing teardown code, the current best practice for setup and teardown is to use yield instead of return...
Read more >Decorator to Memoize Sync or Async Functions in Python
One issue is that this @memoize decorator only works for sync functions; async functions immediately return an awaitable coroutine, and so this ...
Read more >Test Fixtures and Test Listeners (Test Hooks) - Katalon Docs
Add setUp and tearDown in manual view of a test case ; Set Up, This method is always called first, before executing the...
Read more >unittest.mock — mock object library — Python 3.11.1 ...
You can also specify return values and set needed attributes in the normal way. Additionally, mock provides a patch() decorator that handles patching...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As it turns out
contextlib.AsyncExitStack
can do all the cleanup job for us. All we need to do is register all context managers in it.@mastern2k3 thanks for the feedback! It’s very informative! I’m appreciated your effort 👍
I’m totally agree with direction of your thoughts on this 👏
Even added one more thing to teardown logic https://github.com/proofit404/dependencies/issues/549
Problems with order and some parts of error handling could be easily addressed. I’m planning to do it during next week.
Behavior of collecting errors into some kind of group could take more time, and I still want to give myself a chance to think more about this problem before jumping into implementation of the first thing which came to my mind.
I would provide additional details in newly created tickets 🧑🏭
Have a good day 🌴 🍸
Cheers, Artem.