From d4ebb1b78637926e0397ff778f3a41fede585373 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Fri, 5 Mar 2021 20:17:28 -0500 Subject: [PATCH] Remove unittest2 (#419) * Remove unittest2 framework * Skip a couple of tests on Python 2.7 * Update changelog --- Makefile | 4 ++-- docs/main/changelog.rst | 1 + requirements-dev.txt | 1 - .../unit/containers/test_declarative_py2_py3.py | 2 +- .../test_dynamic_async_resources_py36.py | 2 +- tests/unit/containers/test_dynamic_py2_py3.py | 2 +- tests/unit/ext/test_flask_py2_py3.py | 2 +- tests/unit/providers/test_base_py2_py3.py | 2 +- tests/unit/providers/test_callables_py2_py3.py | 2 +- .../providers/test_configuration_py2_py3.py | 5 ++++- tests/unit/providers/test_container_py2_py3.py | 2 +- tests/unit/providers/test_coroutines_py35.py | 2 +- tests/unit/providers/test_dict_py2_py3.py | 2 +- tests/unit/providers/test_factories_py2_py3.py | 2 +- tests/unit/providers/test_injections_py2_py3.py | 2 +- tests/unit/providers/test_list_py2_py3.py | 2 +- .../providers/test_provided_instance_py2_py3.py | 2 +- tests/unit/providers/test_resource_py35.py | 2 +- tests/unit/providers/test_selector_py2_py3.py | 2 +- tests/unit/providers/test_singletons_py2_py3.py | 2 +- tests/unit/providers/test_utils_py2_py3.py | 2 +- tests/unit/test_common_py2_py3.py | 2 +- tox.ini | 17 ++++++----------- 23 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index b2669af0..a7ef1e43 100644 --- a/Makefile +++ b/Makefile @@ -48,14 +48,14 @@ uninstall: test-py2: build # Unit tests with coverage report coverage erase - coverage run --rcfile=./.coveragerc -m unittest2 discover -s tests/unit/ -p test_*_py2_py3.py + coverage run --rcfile=./.coveragerc -m unittest discover -s tests/unit/ -p test_*_py2_py3.py coverage report --rcfile=./.coveragerc coverage html --rcfile=./.coveragerc test: build # Unit tests with coverage report coverage erase - coverage run --rcfile=./.coveragerc -m unittest2 discover -s tests/unit/ -p test_*py3*.py + coverage run --rcfile=./.coveragerc -m unittest discover -s tests/unit/ -p test_*py3*.py coverage report --rcfile=./.coveragerc coverage html --rcfile=./.coveragerc diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 9261dbb4..f583f705 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -14,6 +14,7 @@ follows `Semantic versioning`_ Thanks to `@GitterRemote `_ for reporting the issue. - Add docs and example for ``Factory.add_attributes()`` method. - Remove legacy css file. +- Remove ``unittest2`` test dependency. 4.29.0 ------ diff --git a/requirements-dev.txt b/requirements-dev.txt index 4ae422ed..062b9272 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,5 @@ cython==0.29.21 tox -unittest2 coverage flake8 pydocstyle diff --git a/tests/unit/containers/test_declarative_py2_py3.py b/tests/unit/containers/test_declarative_py2_py3.py index 71184713..a25ed8ce 100644 --- a/tests/unit/containers/test_declarative_py2_py3.py +++ b/tests/unit/containers/test_declarative_py2_py3.py @@ -1,7 +1,7 @@ """Dependency injector declarative container unit tests.""" import collections -import unittest2 as unittest +import unittest from dependency_injector import ( containers, diff --git a/tests/unit/containers/test_dynamic_async_resources_py36.py b/tests/unit/containers/test_dynamic_async_resources_py36.py index f11d0cd8..5053c2a2 100644 --- a/tests/unit/containers/test_dynamic_async_resources_py36.py +++ b/tests/unit/containers/test_dynamic_async_resources_py36.py @@ -1,6 +1,6 @@ """Dependency injector dynamic container unit tests for async resources.""" -import unittest2 as unittest +import unittest # Runtime import to get asyncutils module import os diff --git a/tests/unit/containers/test_dynamic_py2_py3.py b/tests/unit/containers/test_dynamic_py2_py3.py index fb794db7..efa816d7 100644 --- a/tests/unit/containers/test_dynamic_py2_py3.py +++ b/tests/unit/containers/test_dynamic_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector dynamic container unit tests.""" -import unittest2 as unittest +import unittest from dependency_injector import ( containers, diff --git a/tests/unit/ext/test_flask_py2_py3.py b/tests/unit/ext/test_flask_py2_py3.py index 49cf3d5f..fcd1c526 100644 --- a/tests/unit/ext/test_flask_py2_py3.py +++ b/tests/unit/ext/test_flask_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector Flask extension unit tests.""" -import unittest2 as unittest +import unittest from flask import Flask, url_for from flask.views import MethodView diff --git a/tests/unit/providers/test_base_py2_py3.py b/tests/unit/providers/test_base_py2_py3.py index b2978a88..83ac61b5 100644 --- a/tests/unit/providers/test_base_py2_py3.py +++ b/tests/unit/providers/test_base_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector base providers unit tests.""" -import unittest2 as unittest +import unittest from dependency_injector import ( containers, diff --git a/tests/unit/providers/test_callables_py2_py3.py b/tests/unit/providers/test_callables_py2_py3.py index dcee8478..d24fd6eb 100644 --- a/tests/unit/providers/test_callables_py2_py3.py +++ b/tests/unit/providers/test_callables_py2_py3.py @@ -2,7 +2,7 @@ import sys -import unittest2 as unittest +import unittest from dependency_injector import ( providers, diff --git a/tests/unit/providers/test_configuration_py2_py3.py b/tests/unit/providers/test_configuration_py2_py3.py index 21837ab6..1036e3c2 100644 --- a/tests/unit/providers/test_configuration_py2_py3.py +++ b/tests/unit/providers/test_configuration_py2_py3.py @@ -6,7 +6,7 @@ import os import sys import tempfile -import unittest2 as unittest +import unittest from dependency_injector import containers, providers, errors try: @@ -106,6 +106,7 @@ class ConfigTests(unittest.TestCase): self.assertEqual(value, decimal.Decimal('123.123')) + @unittest.skipIf(sys.version_info[:2] == (2, 7), 'Python 2.7 does not support this assert') def test_required(self): provider = providers.Callable( lambda value: value, @@ -218,11 +219,13 @@ class ConfigTests(unittest.TestCase): def test_value_of_undefined_option(self): self.assertIsNone(self.config.a()) + @unittest.skipIf(sys.version_info[:2] == (2, 7), 'Python 2.7 does not support this assert') def test_value_of_undefined_option_in_strict_mode(self): self.config = providers.Configuration(strict=True) with self.assertRaisesRegex(errors.Error, 'Undefined configuration option "config.a"'): self.config.a() + @unittest.skipIf(sys.version_info[:2] == (2, 7), 'Python 2.7 does not support this assert') def test_value_of_undefined_option_with_root_none_in_strict_mode(self): self.config = providers.Configuration(strict=True) self.config.override(None) diff --git a/tests/unit/providers/test_container_py2_py3.py b/tests/unit/providers/test_container_py2_py3.py index 15ba3303..b31caeb4 100644 --- a/tests/unit/providers/test_container_py2_py3.py +++ b/tests/unit/providers/test_container_py2_py3.py @@ -2,7 +2,7 @@ import copy -import unittest2 as unittest +import unittest from dependency_injector import containers, providers, errors diff --git a/tests/unit/providers/test_coroutines_py35.py b/tests/unit/providers/test_coroutines_py35.py index b0dbf491..c19a58c9 100644 --- a/tests/unit/providers/test_coroutines_py35.py +++ b/tests/unit/providers/test_coroutines_py35.py @@ -2,7 +2,7 @@ import asyncio -import unittest2 as unittest +import unittest from dependency_injector import ( providers, diff --git a/tests/unit/providers/test_dict_py2_py3.py b/tests/unit/providers/test_dict_py2_py3.py index 06aae22d..d3e163c6 100644 --- a/tests/unit/providers/test_dict_py2_py3.py +++ b/tests/unit/providers/test_dict_py2_py3.py @@ -2,7 +2,7 @@ import sys -import unittest2 as unittest +import unittest from dependency_injector import providers diff --git a/tests/unit/providers/test_factories_py2_py3.py b/tests/unit/providers/test_factories_py2_py3.py index edf7de07..1a6a82e5 100644 --- a/tests/unit/providers/test_factories_py2_py3.py +++ b/tests/unit/providers/test_factories_py2_py3.py @@ -2,7 +2,7 @@ import sys -import unittest2 as unittest +import unittest from dependency_injector import ( providers, diff --git a/tests/unit/providers/test_injections_py2_py3.py b/tests/unit/providers/test_injections_py2_py3.py index dacd4714..a1e2608b 100644 --- a/tests/unit/providers/test_injections_py2_py3.py +++ b/tests/unit/providers/test_injections_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector injections unit tests.""" -import unittest2 as unittest +import unittest from dependency_injector import providers diff --git a/tests/unit/providers/test_list_py2_py3.py b/tests/unit/providers/test_list_py2_py3.py index e303745b..733714a1 100644 --- a/tests/unit/providers/test_list_py2_py3.py +++ b/tests/unit/providers/test_list_py2_py3.py @@ -2,7 +2,7 @@ import sys -import unittest2 as unittest +import unittest from dependency_injector import providers diff --git a/tests/unit/providers/test_provided_instance_py2_py3.py b/tests/unit/providers/test_provided_instance_py2_py3.py index 814b341b..d1e8345b 100644 --- a/tests/unit/providers/test_provided_instance_py2_py3.py +++ b/tests/unit/providers/test_provided_instance_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector provided instance provider unit tests.""" -import unittest2 as unittest +import unittest from dependency_injector import containers, providers diff --git a/tests/unit/providers/test_resource_py35.py b/tests/unit/providers/test_resource_py35.py index b0943968..b32acf17 100644 --- a/tests/unit/providers/test_resource_py35.py +++ b/tests/unit/providers/test_resource_py35.py @@ -2,7 +2,7 @@ import asyncio -import unittest2 as unittest +import unittest from dependency_injector import containers, providers, resources, errors diff --git a/tests/unit/providers/test_selector_py2_py3.py b/tests/unit/providers/test_selector_py2_py3.py index ee86bcc2..f9cd16b5 100644 --- a/tests/unit/providers/test_selector_py2_py3.py +++ b/tests/unit/providers/test_selector_py2_py3.py @@ -4,7 +4,7 @@ import functools import itertools import sys -import unittest2 as unittest +import unittest from dependency_injector import providers, errors diff --git a/tests/unit/providers/test_singletons_py2_py3.py b/tests/unit/providers/test_singletons_py2_py3.py index 23883282..24a8c73f 100644 --- a/tests/unit/providers/test_singletons_py2_py3.py +++ b/tests/unit/providers/test_singletons_py2_py3.py @@ -2,7 +2,7 @@ import sys -import unittest2 as unittest +import unittest from dependency_injector import ( providers, diff --git a/tests/unit/providers/test_utils_py2_py3.py b/tests/unit/providers/test_utils_py2_py3.py index 880e2fa5..4cebd190 100644 --- a/tests/unit/providers/test_utils_py2_py3.py +++ b/tests/unit/providers/test_utils_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector provider utils unit tests.""" -import unittest2 as unittest +import unittest from dependency_injector import ( providers, diff --git a/tests/unit/test_common_py2_py3.py b/tests/unit/test_common_py2_py3.py index 1a2d1f73..5eb70038 100644 --- a/tests/unit/test_common_py2_py3.py +++ b/tests/unit/test_common_py2_py3.py @@ -1,6 +1,6 @@ """Dependency injector common unit tests.""" -import unittest2 as unittest +import unittest from dependency_injector import __version__ diff --git a/tox.ini b/tox.ini index 1b4e28c8..b35ebac7 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,6 @@ envlist= [testenv] deps= - unittest2 # TODO: Hotfix, remove when fixed https://github.com/aio-libs/aiohttp/issues/5107 typing_extensions httpx @@ -15,7 +14,7 @@ extras= flask aiohttp commands= - unit2 discover -s tests/unit -p test_*_py3*.py + python -m unittest discover -s tests/unit -p test_*_py3*.py [testenv:coveralls] passenv = GITHUB_* COVERALLS_* @@ -28,44 +27,40 @@ deps= coveralls commands= coverage erase - coverage run --rcfile=./.coveragerc -m unittest2 discover -s tests/unit/ -p test_*_py3*.py + coverage run --rcfile=./.coveragerc -m unittest discover -s tests/unit/ -p test_*_py3*.py coverage report --rcfile=./.coveragerc coveralls [testenv:2.7] deps= - unittest2 extras= yaml flask commands= - unit2 discover -s tests/unit -p test_*_py2_py3.py + python -m unittest discover -s tests/unit -p test_*_py2_py3.py [testenv:3.4] deps= - unittest2 extras= flask commands= - unit2 discover -s tests/unit -p test_*_py3.py + python -m unittest discover -s tests/unit -p test_*_py3.py [testenv:3.5] deps= - unittest2 extras= yaml flask commands= - unit2 discover -s tests/unit -p test_*_py3.py + python -m unittest discover -s tests/unit -p test_*_py3.py [testenv:pypy2] deps= - unittest2 extras= yaml flask commands= - unit2 discover -s tests/unit -p test_*_py2_py3.py + python -m unittest discover -s tests/unit -p test_*_py2_py3.py [testenv:pylint] deps=