From 308ac3138c2739feaf1587a598e4d77b7068c936 Mon Sep 17 00:00:00 2001 From: Dominik Rumian Date: Mar 21 2022 12:39:03 +0000 Subject: WIP: Remove python3-mock dependency from fedpkg This commit introduces use of unittest.mock on Python3. Jira: RHELCMP-8616 And https://fedoraproject.org/wiki/Changes/DeprecatePythonMock#How_to_migrate_to_unittest.mock Relates: https://bugzilla.redhat.com/show_bug.cgi?id=2061765 Signed-off-by: Dominik Rumian --- diff --git a/test/test_bugzilla.py b/test/test_bugzilla.py index 2728274..83b608e 100644 --- a/test/test_bugzilla.py +++ b/test/test_bugzilla.py @@ -11,12 +11,16 @@ # the full text of the license. import six -from mock import Mock, patch from fedpkg.bugzilla import BugzillaClient from pyrpkg import rpkgError from utils import unittest +try: + from unittest.mock import Mock, patch +except ImportError: + from mock import Mock, patch + class BugzillaSideEffect(object): def __init__(self): diff --git a/test/test_cli.py b/test/test_cli.py index 7bc5aef..957cefe 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -22,7 +22,6 @@ from tempfile import mkdtemp, mkstemp import git import pkg_resources import six -from mock import Mock, PropertyMock, call, patch from six.moves import StringIO from six.moves.configparser import NoOptionError, NoSectionError @@ -39,6 +38,11 @@ except ImportError: import unittest try: + from unittest.mock import Mock, PropertyMock, call, patch +except ImportError: + from mock import Mock, PropertyMock, call, patch + +try: import bodhi except ImportError: bodhi = None diff --git a/test/test_commands.py b/test/test_commands.py index e9fefb7..c7467ae 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -10,12 +10,16 @@ # the full text of the license. import six -from mock import Mock, PropertyMock, call, mock_open, patch from six.moves import builtins from pyrpkg.errors import rpkgError from utils import CommandTestCase +try: + from unittest.mock import Mock, PropertyMock, call, mock_open, patch +except ImportError: + from mock import Mock, PropertyMock, call, mock_open, patch + class TestDetermineRuntimeEnv(CommandTestCase): """Test Commands._determine_runtime_env""" diff --git a/test/test_retire.py b/test/test_retire.py index d62d1ff..112e817 100644 --- a/test/test_retire.py +++ b/test/test_retire.py @@ -5,12 +5,16 @@ import shutil import subprocess import tempfile -import mock from six.moves import configparser from fedpkg.cli import fedpkgClient from utils import unittest +try: + from unittest import mock +except ImportError: + import mock + TEST_CONFIG = os.path.join(os.path.dirname(__file__), 'fedpkg-test.conf') diff --git a/test/test_utils.py b/test/test_utils.py index 989a4f7..49dc1da 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -13,7 +13,6 @@ import json import six -from mock import Mock, patch from requests.exceptions import ConnectionError from six.moves.configparser import NoOptionError, NoSectionError @@ -22,6 +21,11 @@ from freezegun import freeze_time from pyrpkg.errors import rpkgError from utils import unittest +try: + from unittest.mock import Mock, patch +except ImportError: + from mock import Mock, patch + class TestUtils(unittest.TestCase): """Test functions in fedpkg.utils""" diff --git a/tests-requirements.txt b/tests-requirements.txt index be75121..a700317 100644 --- a/tests-requirements.txt +++ b/tests-requirements.txt @@ -1,4 +1,4 @@ -mock >= 1.0.1 +mock >= 1.0.1;python_version<"3.3" coverage<5.0.0 cccolutils gitpython