Fix a bug in the ``Configuration`` provider to correctly handle overriding by ``None``.

This commit is contained in:
Roman Mogylatov 2021-01-15 06:44:24 -05:00
parent 1cbd3a0215
commit 1c87a9973d
3 changed files with 3176 additions and 3131 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1507,6 +1507,8 @@ cdef class Configuration(Object):
:return: Overriding context.
:rtype: :py:class:`OverridingContext`
"""
if provider is None:
provider = {}
context = super().override(provider)
self.reset_cache()
return context

View File

@ -185,6 +185,13 @@ class ConfigTests(unittest.TestCase):
with self.assertRaises(AttributeError):
a.__name__
def test_missing_key(self):
# See: https://github.com/ets-labs/python-dependency-injector/issues/358
self.config.override(None)
value = self.config.key()
self.assertIsNone(value)
def test_deepcopy(self):
provider = providers.Configuration('config')
provider_copy = providers.deepcopy(provider)