mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-11 09:00:57 +03:00
🎨 Raise exception instead of hiding it in finally (#845)
This commit is contained in:
parent
d82d9fb822
commit
f9db578c59
|
@ -3222,8 +3222,8 @@ cdef class ThreadLocalSingleton(BaseSingleton):
|
||||||
return future_result
|
return future_result
|
||||||
|
|
||||||
self._storage.instance = instance
|
self._storage.instance = instance
|
||||||
finally:
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def _async_init_instance(self, future_result, result):
|
def _async_init_instance(self, future_result, result):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from dependency_injector.containers import Container
|
||||||
|
from dependency_injector.providers import ThreadLocalSingleton
|
||||||
|
|
||||||
|
|
||||||
|
class FailingClass:
|
||||||
|
def __init__(self):
|
||||||
|
raise ValueError("FAILING CLASS")
|
||||||
|
|
||||||
|
|
||||||
|
class TestContainer(Container):
|
||||||
|
failing_class = ThreadLocalSingleton(FailingClass)
|
||||||
|
|
||||||
|
|
||||||
|
def test_on_failure_value_error_is_raised():
|
||||||
|
container = TestContainer()
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match="FAILING CLASS"):
|
||||||
|
container.failing_class()
|
Loading…
Reference in New Issue
Block a user