question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Synchronous setup and teardown for @value decorator.

See original GitHub issue

Value 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
thedrowcommented, Jul 26, 2019

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.

0reactions
proofit404commented, Jun 5, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found