Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on the external module mock #9266

Closed
mcepl opened this issue Dec 11, 2020 · 2 comments
Closed

Remove dependency on the external module mock #9266

mcepl opened this issue Dec 11, 2020 · 2 comments

Comments

@mcepl
Copy link

mcepl commented Dec 11, 2020

Since Python 3.3 mock is present the Python’s standard library, so it is not necessary to use external module. This patch removes the need of using it:

--- a/tests/lib/server.py
+++ b/tests/lib/server.py
@@ -5,7 +5,7 @@ import threading
 from contextlib import contextmanager
 from textwrap import dedent
 
-from mock import Mock
+from unittest.mock import Mock
 from pip._vendor.contextlib2 import nullcontext
 from werkzeug.serving import WSGIRequestHandler
 from werkzeug.serving import make_server as _make_server
--- a/tests/unit/test_base_command.py
+++ b/tests/unit/test_base_command.py
@@ -3,7 +3,7 @@ import os
 import time
 
 import pytest
-from mock import Mock, patch
+from unittest.mock import Mock, patch
 
 from pip._internal.cli.base_command import Command
 from pip._internal.cli.status_codes import SUCCESS
--- a/tests/unit/test_commands.py
+++ b/tests/unit/test_commands.py
@@ -1,5 +1,5 @@
 import pytest
-from mock import patch
+from unittest.mock import patch
 
 from pip._internal.cli.req_command import (
     IndexGroupCommand,
--- a/tests/unit/test_network_cache.py
+++ b/tests/unit/test_network_cache.py
@@ -1,7 +1,7 @@
 import os
 
 import pytest
-from mock import Mock
+from unittest.mock import Mock
 from pip._vendor.cachecontrol.caches import FileCache
 
 from pip._internal.network.cache import SafeFileCache
--- a/tests/unit/test_req_file.py
+++ b/tests/unit/test_req_file.py
@@ -5,7 +5,7 @@ import subprocess
 import textwrap
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 from pip._vendor.six import PY2
 from pretend import stub
 
--- a/tests/unit/test_resolution_legacy_resolver.py
+++ b/tests/unit/test_resolution_legacy_resolver.py
@@ -1,6 +1,6 @@
 import logging
 
-import mock
+import unittest.mock
 import pytest
 from pip._vendor import pkg_resources
 
--- a/tests/unit/test_target_python.py
+++ b/tests/unit/test_target_python.py
@@ -1,5 +1,5 @@
 import pytest
-from mock import patch
+from unittest.mock import patch
 
 from pip._internal.models.target_python import TargetPython
 from tests.lib import CURRENT_PY_VERSION_INFO, pyversion
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -14,7 +14,7 @@ import time
 from io import BytesIO
 
 import pytest
-from mock import Mock, patch
+from unittest.mock import Mock, patch
 
 from pip._internal.exceptions import (
     HashMismatch,
--- a/tests/unit/test_utils_compatibility_tags.py
+++ b/tests/unit/test_utils_compatibility_tags.py
@@ -1,7 +1,7 @@
 import sysconfig
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 
 from pip._internal.utils import compatibility_tags
 
--- a/tests/unit/test_vcs.py
+++ b/tests/unit/test_vcs.py
@@ -2,7 +2,7 @@ import os
 from unittest import TestCase
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 from pip._vendor.packaging.version import parse as parse_version
 
 from pip._internal.exceptions import BadCommand, InstallationError
--- a/tests/unit/test_wheel.py
+++ b/tests/unit/test_wheel.py
@@ -8,7 +8,7 @@ import textwrap
 from email import message_from_string
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 from pip._vendor.packaging.requirements import Requirement
 
 from pip._internal.exceptions import InstallationError
--- a/tests/unit/test_wheel_builder.py
+++ b/tests/unit/test_wheel_builder.py
@@ -1,7 +1,7 @@
 import logging
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 
 from pip._internal import wheel_builder
 from pip._internal.models.link import Link
--- a/tests/functional/test_help.py
+++ b/tests/functional/test_help.py
@@ -1,5 +1,5 @@
 import pytest
-from mock import Mock
+from unittest.mock import Mock
 
 from pip._internal.cli.status_codes import ERROR, SUCCESS
 from pip._internal.commands import commands_dict, create_command
--- a/tests/unit/resolution_resolvelib/test_resolver.py
+++ b/tests/unit/resolution_resolvelib/test_resolver.py
@@ -1,4 +1,4 @@
-import mock
+import unittest.mock as mock
 import pytest
 from pip._vendor.packaging.utils import canonicalize_name
 from pip._vendor.resolvelib.resolvers import Result
--- a/tests/unit/test_check.py
+++ b/tests/unit/test_check.py
@@ -1,7 +1,7 @@
 """Unit Tests for pip's dependency checking logic
 """
 
-import mock
+import unittest.mock
 
 from pip._internal.operations import check
 
--- a/tests/unit/test_collector.py
+++ b/tests/unit/test_collector.py
@@ -4,10 +4,10 @@ import re
 import uuid
 from textwrap import dedent
 
-import mock
+import unittest.mock as mock
 import pretend
 import pytest
-from mock import Mock, patch
+from unittest.mock import Mock, patch
 from pip._vendor import html5lib, requests
 from pip._vendor.six.moves.urllib import request as urllib_request
 
--- a/tests/unit/test_command_install.py
+++ b/tests/unit/test_command_install.py
@@ -1,7 +1,7 @@
 import errno
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 from pip._vendor.packaging.requirements import Requirement
 
 from pip._internal.commands.install import (
--- a/tests/unit/test_configuration.py
+++ b/tests/unit/test_configuration.py
@@ -4,7 +4,7 @@
 import os
 
 import pytest
-from mock import MagicMock
+from unittest.mock import MagicMock
 
 from pip._internal.configuration import get_configuration_files, kinds
 from pip._internal.exceptions import ConfigurationError
--- a/tests/unit/test_direct_url_helpers.py
+++ b/tests/unit/test_direct_url_helpers.py
@@ -1,6 +1,6 @@
 from functools import partial
 
-from mock import MagicMock, patch
+from unittest.mock import MagicMock, patch
 
 from pip._internal.models.direct_url import (
     DIRECT_URL_METADATA_NAME,
--- a/tests/unit/test_finder.py
+++ b/tests/unit/test_finder.py
@@ -2,7 +2,7 @@ import logging
 import sys
 
 import pytest
-from mock import Mock, patch
+from unittest.mock import Mock, patch
 from pip._vendor.packaging.specifiers import SpecifierSet
 from pip._vendor.packaging.tags import Tag
 from pkg_resources import parse_version
--- a/tests/unit/test_locations.py
+++ b/tests/unit/test_locations.py
@@ -9,7 +9,7 @@ import sys
 import tempfile
 
 import pytest
-from mock import Mock
+from unittest.mock import Mock
 
 from pip._internal.locations import distutils_scheme
 
--- a/tests/unit/test_logging.py
+++ b/tests/unit/test_logging.py
@@ -5,7 +5,7 @@ import time
 from threading import Thread
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 from pip._vendor.six import PY2
 
 from pip._internal.utils.logging import (
--- a/tests/unit/test_operations_prepare.py
+++ b/tests/unit/test_operations_prepare.py
@@ -4,7 +4,7 @@ from shutil import rmtree
 from tempfile import mkdtemp
 
 import pytest
-from mock import Mock, patch
+from unittest.mock import Mock, patch
 
 from pip._internal.exceptions import HashMismatch
 from pip._internal.models.link import Link
--- a/tests/unit/test_req.py
+++ b/tests/unit/test_req.py
@@ -6,7 +6,7 @@ import tempfile
 from functools import partial
 
 import pytest
-from mock import patch
+from unittest.mock import patch
 from pip._vendor import pkg_resources
 from pip._vendor.packaging.markers import Marker
 from pip._vendor.packaging.requirements import Requirement
--- a/tests/unit/test_req_uninstall.py
+++ b/tests/unit/test_req_uninstall.py
@@ -2,7 +2,7 @@ import os
 import sys
 
 import pytest
-from mock import Mock
+from unittest.mock import Mock
 
 import pip._internal.req.req_uninstall
 from pip._internal.req.req_uninstall import (
@pradyunsg
Copy link
Member

pradyunsg commented Dec 12, 2020

Thanks for filing this issue!

The reason for the external dependency is that, as of right now, pip's master branch still supports Python 2.

@pradyunsg
Copy link
Member

Closing since this is covered by #8802.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Dec 16, 2020
https://build.opensuse.org/request/show/855625
by user mcepl + dimstar_suse
- Fix the condition to really not break Python 2.7 in Leap

- We don't need to break Python 2.7

- Add remove_mock.patch to remove dependency on the external mock
  package (gh#pypa/pip#9266).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants