From 41cf1bd6b416b164c0fa027ff7dcdadd90e7c8d7 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sat, 6 Mar 2021 08:58:30 -0500 Subject: [PATCH] Fix warnings in tests --- .../containers/test_declarative_py2_py3.py | 2 +- tests/unit/providers/test_async_py36.py | 2 +- tests/unit/providers/test_base_py2_py3.py | 8 +++++--- tests/unit/providers/test_coroutines_py35.py | 20 ++++++++++++------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/unit/containers/test_declarative_py2_py3.py b/tests/unit/containers/test_declarative_py2_py3.py index a25ed8ce..8bf8b8e2 100644 --- a/tests/unit/containers/test_declarative_py2_py3.py +++ b/tests/unit/containers/test_declarative_py2_py3.py @@ -412,7 +412,7 @@ class DeclarativeContainerTests(unittest.TestCase): class Services(containers.DeclarativeContainer): a = providers.Dependency() c = providers.Factory(C, a=a) - b = providers.Factory(B, fa=a.delegate()) + b = providers.Factory(B, fa=a.provider) a = providers.Factory(A) assert isinstance(Services(a=a).c().a, A) # ok diff --git a/tests/unit/providers/test_async_py36.py b/tests/unit/providers/test_async_py36.py index 81510efc..16ddec6d 100644 --- a/tests/unit/providers/test_async_py36.py +++ b/tests/unit/providers/test_async_py36.py @@ -996,7 +996,7 @@ class AsyncProvidersWithAsyncDependenciesTests(AsyncTestCase): container = Container() service = self._run(container.service()) - self.assertEquals(service, {'service': 'ok', 'db': {'db': 'ok'}}) + self.assertEqual(service, {'service': 'ok', 'db': {'db': 'ok'}}) class AsyncProviderWithAwaitableObjectTests(AsyncTestCase): diff --git a/tests/unit/providers/test_base_py2_py3.py b/tests/unit/providers/test_base_py2_py3.py index 83ac61b5..55730089 100644 --- a/tests/unit/providers/test_base_py2_py3.py +++ b/tests/unit/providers/test_base_py2_py3.py @@ -1,6 +1,7 @@ """Dependency injector base providers unit tests.""" import unittest +import warnings from dependency_injector import ( containers, @@ -21,13 +22,14 @@ class ProviderTests(unittest.TestCase): self.assertRaises(NotImplementedError, self.provider.__call__) def test_delegate(self): - delegate1 = self.provider.delegate() + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + delegate1 = self.provider.delegate() + delegate2 = self.provider.delegate() self.assertIsInstance(delegate1, providers.Delegate) self.assertIs(delegate1(), self.provider) - delegate2 = self.provider.delegate() - self.assertIsInstance(delegate2, providers.Delegate) self.assertIs(delegate2(), self.provider) diff --git a/tests/unit/providers/test_coroutines_py35.py b/tests/unit/providers/test_coroutines_py35.py index c19a58c9..f5217496 100644 --- a/tests/unit/providers/test_coroutines_py35.py +++ b/tests/unit/providers/test_coroutines_py35.py @@ -1,8 +1,8 @@ """Dependency injector coroutine providers unit tests.""" import asyncio - import unittest +import warnings from dependency_injector import ( providers, @@ -232,9 +232,12 @@ class AbstractCoroutineTests(AsyncTestCase): providers.Coroutine) def test_call_overridden_by_coroutine(self): - @asyncio.coroutine - def _abstract_example(): - raise RuntimeError('Should not be raised') + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + + @asyncio.coroutine + def _abstract_example(): + raise RuntimeError('Should not be raised') provider = providers.AbstractCoroutine(_abstract_example) provider.override(providers.Coroutine(_example)) @@ -242,9 +245,12 @@ class AbstractCoroutineTests(AsyncTestCase): self.assertTrue(self._run(provider(1, 2, 3, 4)), (1, 2, 3, 4)) def test_call_overridden_by_delegated_coroutine(self): - @asyncio.coroutine - def _abstract_example(): - raise RuntimeError('Should not be raised') + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + + @asyncio.coroutine + def _abstract_example(): + raise RuntimeError('Should not be raised') provider = providers.AbstractCoroutine(_abstract_example) provider.override(providers.DelegatedCoroutine(_example))