Repository: certbot/certbot

Issue:
Remove the third-party `mock` dependency
>Functions in certbot.tests.util were previously using the third party mock module if it was available for backwards compatibiliy. This behavior will be removed and unittest.mock from the standard library will always be used instead.

e.g. https://github.com/certbot/certbot/blob/5c111d0bd1206d864d7cb93754e101f6073bc669/certbot/certbot/tests/util.py#L38-L50






Discussion:

Resolving patch:
diff --git a/certbot/setup.py b/certbot/setup.py
--- a/certbot/setup.py
+++ b/certbot/setup.py
@@ -90,7 +90,6 @@ def read_file(filename, encoding='utf8'):
     'pytest-xdist',
     'setuptools',
     'tox',
-    'types-mock',
     'types-pyOpenSSL',
     'types-pyRFC3339',
     'types-pytz',


Test patch:
diff --git a/certbot-apache/tests/augeasnode_test.py b/certbot-apache/tests/augeasnode_test.py
--- a/certbot-apache/tests/augeasnode_test.py
+++ b/certbot-apache/tests/augeasnode_test.py
@@ -1,13 +1,9 @@
 """Tests for AugeasParserNode classes"""
 from typing import List
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
-
 import os
 import util
+from unittest import mock
 
 from certbot import errors
 
diff --git a/certbot-apache/tests/autohsts_test.py b/certbot-apache/tests/autohsts_test.py
--- a/certbot-apache/tests/autohsts_test.py
+++ b/certbot-apache/tests/autohsts_test.py
@@ -2,11 +2,7 @@
 """Test for certbot_apache._internal.configurator AutoHSTS functionality"""
 import re
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot_apache._internal import constants
diff --git a/certbot-apache/tests/centos_test.py b/certbot-apache/tests/centos_test.py
--- a/certbot-apache/tests/centos_test.py
+++ b/certbot-apache/tests/centos_test.py
@@ -1,10 +1,6 @@
 """Test for certbot_apache._internal.configurator for Centos overrides"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import filesystem
diff --git a/certbot-apache/tests/configurator_reverter_test.py b/certbot-apache/tests/configurator_reverter_test.py
--- a/certbot-apache/tests/configurator_reverter_test.py
+++ b/certbot-apache/tests/configurator_reverter_test.py
@@ -1,11 +1,7 @@
 """Test for certbot_apache._internal.configurator implementations of reverter"""
 import shutil
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 import util
diff --git a/certbot-apache/tests/configurator_test.py b/certbot-apache/tests/configurator_test.py
--- a/certbot-apache/tests/configurator_test.py
+++ b/certbot-apache/tests/configurator_test.py
@@ -5,11 +5,7 @@
 import socket
 import tempfile
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from acme import challenges
 from certbot import achallenges
diff --git a/certbot-apache/tests/debian_test.py b/certbot-apache/tests/debian_test.py
--- a/certbot-apache/tests/debian_test.py
+++ b/certbot-apache/tests/debian_test.py
@@ -1,11 +1,7 @@
 """Test for certbot_apache._internal.configurator for Debian overrides"""
 import shutil
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-apache/tests/display_ops_test.py b/certbot-apache/tests/display_ops_test.py
--- a/certbot-apache/tests/display_ops_test.py
+++ b/certbot-apache/tests/display_ops_test.py
@@ -1,10 +1,6 @@
 """Test certbot_apache._internal.display_ops."""
 import unittest
-
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.display import util as display_util
diff --git a/certbot-apache/tests/dualnode_test.py b/certbot-apache/tests/dualnode_test.py
--- a/certbot-apache/tests/dualnode_test.py
+++ b/certbot-apache/tests/dualnode_test.py
@@ -1,10 +1,6 @@
 """Tests for DualParserNode implementation"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot_apache._internal import assertions
 from certbot_apache._internal import augeasparser
diff --git a/certbot-apache/tests/entrypoint_test.py b/certbot-apache/tests/entrypoint_test.py
--- a/certbot-apache/tests/entrypoint_test.py
+++ b/certbot-apache/tests/entrypoint_test.py
@@ -1,10 +1,6 @@
 """Test for certbot_apache._internal.entrypoint for override class resolution"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot_apache._internal import configurator
 from certbot_apache._internal import entrypoint
diff --git a/certbot-apache/tests/fedora_test.py b/certbot-apache/tests/fedora_test.py
--- a/certbot-apache/tests/fedora_test.py
+++ b/certbot-apache/tests/fedora_test.py
@@ -1,10 +1,6 @@
 """Test for certbot_apache._internal.configurator for Fedora 29+ overrides"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import filesystem
diff --git a/certbot-apache/tests/gentoo_test.py b/certbot-apache/tests/gentoo_test.py
--- a/certbot-apache/tests/gentoo_test.py
+++ b/certbot-apache/tests/gentoo_test.py
@@ -1,10 +1,6 @@
 """Test for certbot_apache._internal.configurator for Gentoo overrides"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import filesystem
diff --git a/certbot-apache/tests/http_01_test.py b/certbot-apache/tests/http_01_test.py
--- a/certbot-apache/tests/http_01_test.py
+++ b/certbot-apache/tests/http_01_test.py
@@ -2,11 +2,7 @@
 import unittest
 import errno
 from typing import List
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from acme import challenges
 from certbot import achallenges
diff --git a/certbot-apache/tests/parser_test.py b/certbot-apache/tests/parser_test.py
--- a/certbot-apache/tests/parser_test.py
+++ b/certbot-apache/tests/parser_test.py
@@ -1,11 +1,7 @@
 """Tests for certbot_apache._internal.parser."""
 import shutil
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-apache/tests/parsernode_configurator_test.py b/certbot-apache/tests/parsernode_configurator_test.py
--- a/certbot-apache/tests/parsernode_configurator_test.py
+++ b/certbot-apache/tests/parsernode_configurator_test.py
@@ -1,10 +1,6 @@
 """Tests for ApacheConfigurator for AugeasParserNode classes"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 import util
 
diff --git a/certbot-apache/tests/util.py b/certbot-apache/tests/util.py
--- a/certbot-apache/tests/util.py
+++ b/certbot-apache/tests/util.py
@@ -4,11 +4,7 @@
 
 import augeas
 import josepy as jose
-
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
+from unittest import mock
 
 from certbot.compat import os
 from certbot.plugins import common
diff --git a/certbot-dns-cloudflare/tests/dns_cloudflare_test.py b/certbot-dns-cloudflare/tests/dns_cloudflare_test.py
--- a/certbot-dns-cloudflare/tests/dns_cloudflare_test.py
+++ b/certbot-dns-cloudflare/tests/dns_cloudflare_test.py
@@ -1,12 +1,9 @@
 """Tests for certbot_dns_cloudflare._internal.dns_cloudflare."""
 
 import unittest
+from unittest import mock
 
 import CloudFlare
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-dns-digitalocean/tests/dns_digitalocean_test.py b/certbot-dns-digitalocean/tests/dns_digitalocean_test.py
--- a/certbot-dns-digitalocean/tests/dns_digitalocean_test.py
+++ b/certbot-dns-digitalocean/tests/dns_digitalocean_test.py
@@ -1,12 +1,9 @@
 """Tests for certbot_dns_digitalocean._internal.dns_digitalocean."""
 
 import unittest
+from unittest import mock
 
 import digitalocean
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-dns-dnsimple/tests/dns_dnsimple_test.py b/certbot-dns-dnsimple/tests/dns_dnsimple_test.py
--- a/certbot-dns-dnsimple/tests/dns_dnsimple_test.py
+++ b/certbot-dns-dnsimple/tests/dns_dnsimple_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_dnsimple._internal.dns_dnsimple."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-dns-dnsmadeeasy/tests/dns_dnsmadeeasy_test.py b/certbot-dns-dnsmadeeasy/tests/dns_dnsmadeeasy_test.py
--- a/certbot-dns-dnsmadeeasy/tests/dns_dnsmadeeasy_test.py
+++ b/certbot-dns-dnsmadeeasy/tests/dns_dnsmadeeasy_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_dnsmadeeasy._internal.dns_dnsmadeeasy."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-dns-gehirn/tests/dns_gehirn_test.py b/certbot-dns-gehirn/tests/dns_gehirn_test.py
--- a/certbot-dns-gehirn/tests/dns_gehirn_test.py
+++ b/certbot-dns-gehirn/tests/dns_gehirn_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_gehirn._internal.dns_gehirn."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-dns-google/tests/dns_google_test.py b/certbot-dns-google/tests/dns_google_test.py
--- a/certbot-dns-google/tests/dns_google_test.py
+++ b/certbot-dns-google/tests/dns_google_test.py
@@ -6,10 +6,8 @@
 from googleapiclient.errors import Error
 from googleapiclient.http import HttpMock
 from httplib2 import ServerNotFoundError
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-dns-linode/tests/dns_linode_test.py b/certbot-dns-linode/tests/dns_linode_test.py
--- a/certbot-dns-linode/tests/dns_linode_test.py
+++ b/certbot-dns-linode/tests/dns_linode_test.py
@@ -1,11 +1,7 @@
 """Tests for certbot_dns_linode._internal.dns_linode."""
 
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-dns-luadns/tests/dns_luadns_test.py b/certbot-dns-luadns/tests/dns_luadns_test.py
--- a/certbot-dns-luadns/tests/dns_luadns_test.py
+++ b/certbot-dns-luadns/tests/dns_luadns_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_luadns._internal.dns_luadns."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-dns-nsone/tests/dns_nsone_test.py b/certbot-dns-nsone/tests/dns_nsone_test.py
--- a/certbot-dns-nsone/tests/dns_nsone_test.py
+++ b/certbot-dns-nsone/tests/dns_nsone_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_nsone._internal.dns_nsone."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-dns-ovh/tests/dns_ovh_test.py b/certbot-dns-ovh/tests/dns_ovh_test.py
--- a/certbot-dns-ovh/tests/dns_ovh_test.py
+++ b/certbot-dns-ovh/tests/dns_ovh_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_ovh._internal.dns_ovh."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-dns-rfc2136/tests/dns_rfc2136_test.py b/certbot-dns-rfc2136/tests/dns_rfc2136_test.py
--- a/certbot-dns-rfc2136/tests/dns_rfc2136_test.py
+++ b/certbot-dns-rfc2136/tests/dns_rfc2136_test.py
@@ -1,14 +1,11 @@
 """Tests for certbot_dns_rfc2136._internal.dns_rfc2136."""
 
 import unittest
+from unittest import mock
 
 import dns.flags
 import dns.rcode
 import dns.tsig
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-dns-route53/tests/dns_route53_test.py b/certbot-dns-route53/tests/dns_route53_test.py
--- a/certbot-dns-route53/tests/dns_route53_test.py
+++ b/certbot-dns-route53/tests/dns_route53_test.py
@@ -1,13 +1,10 @@
 """Tests for certbot_dns_route53._internal.dns_route53.Authenticator"""
 
 import unittest
+from unittest import mock
 
 from botocore.exceptions import ClientError
 from botocore.exceptions import NoCredentialsError
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot-dns-sakuracloud/tests/dns_sakuracloud_test.py b/certbot-dns-sakuracloud/tests/dns_sakuracloud_test.py
--- a/certbot-dns-sakuracloud/tests/dns_sakuracloud_test.py
+++ b/certbot-dns-sakuracloud/tests/dns_sakuracloud_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_dns_sakuracloud._internal.dns_sakuracloud."""
 
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 from requests.exceptions import HTTPError
 
 from certbot.compat import os
diff --git a/certbot-nginx/tests/configurator_test.py b/certbot-nginx/tests/configurator_test.py
--- a/certbot-nginx/tests/configurator_test.py
+++ b/certbot-nginx/tests/configurator_test.py
@@ -1,10 +1,7 @@
 """Test for certbot_nginx._internal.configurator."""
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 import OpenSSL
 
 from acme import challenges
diff --git a/certbot-nginx/tests/http_01_test.py b/certbot-nginx/tests/http_01_test.py
--- a/certbot-nginx/tests/http_01_test.py
+++ b/certbot-nginx/tests/http_01_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot_nginx._internal.http_01"""
 import unittest
+from unittest import mock
 
 import josepy as jose
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
 
 from acme import challenges
 from certbot import achallenges
diff --git a/certbot-nginx/tests/parser_obj_test.py b/certbot-nginx/tests/parser_obj_test.py
--- a/certbot-nginx/tests/parser_obj_test.py
+++ b/certbot-nginx/tests/parser_obj_test.py
@@ -1,11 +1,7 @@
 """ Tests for functions and classes in parser_obj.py """
 
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock # type: ignore
+from unittest import mock
 
 from certbot_nginx._internal.parser_obj import COMMENT_BLOCK
 from certbot_nginx._internal.parser_obj import parse_raw
diff --git a/certbot-nginx/tests/test_util.py b/certbot-nginx/tests/test_util.py
--- a/certbot-nginx/tests/test_util.py
+++ b/certbot-nginx/tests/test_util.py
@@ -4,10 +4,7 @@
 import tempfile
 
 import josepy as jose
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
+from unittest import mock
 import pkg_resources
 
 from certbot import util
diff --git a/certbot/certbot/plugins/dns_test_common.py b/certbot/certbot/plugins/dns_test_common.py
--- a/certbot/certbot/plugins/dns_test_common.py
+++ b/certbot/certbot/plugins/dns_test_common.py
@@ -5,6 +5,7 @@
 
 import configobj
 import josepy as jose
+from unittest import mock
 
 from acme import challenges
 from certbot import achallenges
@@ -19,12 +20,6 @@
     Protocol = object
 
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
-
-
 DOMAIN = 'example.com'
 KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
 
diff --git a/certbot/certbot/plugins/dns_test_common_lexicon.py b/certbot/certbot/plugins/dns_test_common_lexicon.py
--- a/certbot/certbot/plugins/dns_test_common_lexicon.py
+++ b/certbot/certbot/plugins/dns_test_common_lexicon.py
@@ -1,6 +1,7 @@
 """Base test class for DNS authenticators built on Lexicon."""
 from typing import Any
 from typing import TYPE_CHECKING
+from unittest import mock
 from unittest.mock import MagicMock
 
 import josepy as jose
@@ -14,10 +15,6 @@
 from certbot.plugins.dns_test_common import _AuthenticatorCallableTestCase
 from certbot.tests import util as test_util
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
 if TYPE_CHECKING:
     from typing_extensions import Protocol
 else:
diff --git a/certbot/certbot/tests/util.py b/certbot/certbot/tests/util.py
--- a/certbot/certbot/tests/util.py
+++ b/certbot/certbot/tests/util.py
@@ -16,7 +16,7 @@
 from typing import List
 from typing import Optional
 import unittest
-import warnings
+from unittest import mock
 
 from cryptography.hazmat.backends import default_backend
 from cryptography.hazmat.primitives import serialization
@@ -35,20 +35,6 @@
 from certbot.display import util as display_util
 from certbot.plugins import common
 
-try:
-    # When we remove this deprecated import, we should also remove the
-    # "external-mock" test environment and the mock dependency listed in
-    # tools/pinning/pyproject.toml.
-    import mock
-    warnings.warn(
-        "The external mock module is being used for backwards compatibility "
-        "since it is available, however, future versions of Certbot's tests will "
-        "use unittest.mock. Be sure to update your code accordingly.",
-        PendingDeprecationWarning
-    )
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
-
 
 class DummyInstaller(common.Installer):
     """Dummy installer plugin for test purpose."""
diff --git a/certbot/tests/account_test.py b/certbot/tests/account_test.py
--- a/certbot/tests/account_test.py
+++ b/certbot/tests/account_test.py
@@ -4,10 +4,7 @@
 import unittest
 
 import josepy as jose
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 import pytz
 
 from acme import messages
diff --git a/certbot/tests/auth_handler_test.py b/certbot/tests/auth_handler_test.py
--- a/certbot/tests/auth_handler_test.py
+++ b/certbot/tests/auth_handler_test.py
@@ -4,10 +4,7 @@
 import unittest
 
 from josepy import b64encode
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from acme import challenges
 from acme import client as acme_client
diff --git a/certbot/tests/cert_manager_test.py b/certbot/tests/cert_manager_test.py
--- a/certbot/tests/cert_manager_test.py
+++ b/certbot/tests/cert_manager_test.py
@@ -7,10 +7,7 @@
 import unittest
 
 import configobj
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors, configuration
 from certbot._internal.storage import ALL_FOUR
diff --git a/certbot/tests/cli_test.py b/certbot/tests/cli_test.py
--- a/certbot/tests/cli_test.py
+++ b/certbot/tests/cli_test.py
@@ -5,6 +5,7 @@
 import io
 import tempfile
 import unittest
+from unittest import mock
 
 from acme import challenges
 from certbot import errors
@@ -16,11 +17,6 @@
 import certbot.tests.util as test_util
 from certbot.tests.util import TempDirTestCase
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
 
 PLUGINS = disco.PluginsRegistry.find_all()
 
diff --git a/certbot/tests/client_test.py b/certbot/tests/client_test.py
--- a/certbot/tests/client_test.py
+++ b/certbot/tests/client_test.py
@@ -5,6 +5,7 @@
 import shutil
 import tempfile
 import unittest
+from unittest import mock
 from unittest.mock import MagicMock
 
 from josepy import interfaces
@@ -17,11 +18,6 @@
 from certbot.compat import os
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
 
 KEY = test_util.load_vector("rsa512_key.pem")
 CSR_SAN = test_util.load_vector("csr-san_512.pem")
diff --git a/certbot/tests/compat/filesystem_test.py b/certbot/tests/compat/filesystem_test.py
--- a/certbot/tests/compat/filesystem_test.py
+++ b/certbot/tests/compat/filesystem_test.py
@@ -2,11 +2,7 @@
 import contextlib
 import errno
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import util
 from certbot._internal import lock
diff --git a/certbot/tests/compat/misc_test.py b/certbot/tests/compat/misc_test.py
--- a/certbot/tests/compat/misc_test.py
+++ b/certbot/tests/compat/misc_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot.compat.misc"""
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock  # type: ignore
 import unittest
-import warnings
+from unittest import mock
 
 from certbot.compat import os
 
diff --git a/certbot/tests/configuration_test.py b/certbot/tests/configuration_test.py
--- a/certbot/tests/configuration_test.py
+++ b/certbot/tests/configuration_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot.configuration."""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors
 from certbot._internal import constants
diff --git a/certbot/tests/crypto_util_test.py b/certbot/tests/crypto_util_test.py
--- a/certbot/tests/crypto_util_test.py
+++ b/certbot/tests/crypto_util_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot.crypto_util."""
 import logging
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
 import OpenSSL
 
 from certbot import errors
diff --git a/certbot/tests/display/completer_test.py b/certbot/tests/display/completer_test.py
--- a/certbot/tests/display/completer_test.py
+++ b/certbot/tests/display/completer_test.py
@@ -9,17 +9,12 @@
 import string
 import sys
 import unittest
+from unittest import mock
 
 from certbot.compat import filesystem
 from certbot.compat import os
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
-
 
 class CompleterTest(test_util.TempDirTestCase):
     """Test certbot._internal.display.completer.Completer."""
diff --git a/certbot/tests/display/internal_util_test.py b/certbot/tests/display/internal_util_test.py
--- a/certbot/tests/display/internal_util_test.py
+++ b/certbot/tests/display/internal_util_test.py
@@ -3,15 +3,11 @@
 import socket
 import tempfile
 import unittest
+from unittest import mock
 
 from acme import messages as acme_messages
 from certbot import errors
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
 
 class WrapLinesTest(unittest.TestCase):
     def test_wrap_lines(self):
diff --git a/certbot/tests/display/ops_test.py b/certbot/tests/display/ops_test.py
--- a/certbot/tests/display/ops_test.py
+++ b/certbot/tests/display/ops_test.py
@@ -2,6 +2,7 @@
 """Test certbot.display.ops."""
 import sys
 import unittest
+from unittest import mock
 
 import josepy as jose
 
@@ -15,11 +16,6 @@
 from certbot.display import util as display_util
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
 
 KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
 
diff --git a/certbot/tests/display/util_test.py b/certbot/tests/display/util_test.py
--- a/certbot/tests/display/util_test.py
+++ b/certbot/tests/display/util_test.py
@@ -3,15 +3,11 @@
 import socket
 import tempfile
 import unittest
+from unittest import mock
 
 from certbot import errors
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
 
 class NotifyTest(unittest.TestCase):
     """Tests for certbot.display.util.notify"""
diff --git a/certbot/tests/eff_test.py b/certbot/tests/eff_test.py
--- a/certbot/tests/eff_test.py
+++ b/certbot/tests/eff_test.py
@@ -1,11 +1,8 @@
 """Tests for certbot._internal.eff."""
 import datetime
 import unittest
+from unittest import mock
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
 import josepy
 import pytz
 import requests
diff --git a/certbot/tests/error_handler_test.py b/certbot/tests/error_handler_test.py
--- a/certbot/tests/error_handler_test.py
+++ b/certbot/tests/error_handler_test.py
@@ -6,15 +6,10 @@
 from typing import Dict
 from typing import Union
 import unittest
+from unittest import mock
 
 from certbot.compat import os
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
-
 
 def get_signals(signums):
     """Get the handlers for an iterable of signums."""
diff --git a/certbot/tests/errors_test.py b/certbot/tests/errors_test.py
--- a/certbot/tests/errors_test.py
+++ b/certbot/tests/errors_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot.errors."""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from acme import messages
 from certbot import achallenges
diff --git a/certbot/tests/helpful_test.py b/certbot/tests/helpful_test.py
--- a/certbot/tests/helpful_test.py
+++ b/certbot/tests/helpful_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot.helpful_parser"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors
 from certbot._internal.cli import HelpfulArgumentParser
diff --git a/certbot/tests/hook_test.py b/certbot/tests/hook_test.py
--- a/certbot/tests/hook_test.py
+++ b/certbot/tests/hook_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot._internal.hooks."""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors
 from certbot import util
diff --git a/certbot/tests/lock_test.py b/certbot/tests/lock_test.py
--- a/certbot/tests/lock_test.py
+++ b/certbot/tests/lock_test.py
@@ -2,11 +2,7 @@
 import functools
 import multiprocessing
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot/tests/log_test.py b/certbot/tests/log_test.py
--- a/certbot/tests/log_test.py
+++ b/certbot/tests/log_test.py
@@ -6,6 +6,7 @@
 import time
 from typing import Optional
 import unittest
+from unittest import mock
 
 from acme import messages
 from certbot import errors
@@ -15,11 +16,6 @@
 from certbot.compat import os
 from certbot.tests import util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
 
 
 class PreArgParseSetupTest(unittest.TestCase):
diff --git a/certbot/tests/main_test.py b/certbot/tests/main_test.py
--- a/certbot/tests/main_test.py
+++ b/certbot/tests/main_test.py
@@ -12,6 +12,7 @@
 import traceback
 from typing import List
 import unittest
+from unittest import mock
 
 import josepy as jose
 import pytz
@@ -34,11 +35,6 @@
 from certbot.plugins import enhancements
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
 
 
 CERT_PATH = test_util.vector_path('cert_512.pem')
diff --git a/certbot/tests/ocsp_test.py b/certbot/tests/ocsp_test.py
--- a/certbot/tests/ocsp_test.py
+++ b/certbot/tests/ocsp_test.py
@@ -4,6 +4,7 @@
 from datetime import datetime
 from datetime import timedelta
 import unittest
+from unittest import mock
 
 from cryptography import x509
 from cryptography.exceptions import InvalidSignature
@@ -16,11 +17,6 @@
 from certbot import errors
 from certbot.tests import util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
 
 out = """Missing = in header key=value
 ocsp: Use -help for summary.
diff --git a/certbot/tests/plugins/common_test.py b/certbot/tests/plugins/common_test.py
--- a/certbot/tests/plugins/common_test.py
+++ b/certbot/tests/plugins/common_test.py
@@ -2,12 +2,9 @@
 import functools
 import shutil
 import unittest
+from unittest import mock
 
 import josepy as jose
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
 
 from acme import challenges
 from certbot import achallenges
diff --git a/certbot/tests/plugins/disco_test.py b/certbot/tests/plugins/disco_test.py
--- a/certbot/tests/plugins/disco_test.py
+++ b/certbot/tests/plugins/disco_test.py
@@ -3,6 +3,7 @@
 import string
 from typing import List
 import unittest
+from unittest import mock
 
 import pkg_resources
 
@@ -12,11 +13,6 @@
 from certbot._internal.plugins import standalone
 from certbot._internal.plugins import webroot
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
 
 EP_SA = pkg_resources.EntryPoint(
     "sa", "certbot._internal.plugins.standalone",
diff --git a/certbot/tests/plugins/dns_common_lexicon_test.py b/certbot/tests/plugins/dns_common_lexicon_test.py
--- a/certbot/tests/plugins/dns_common_lexicon_test.py
+++ b/certbot/tests/plugins/dns_common_lexicon_test.py
@@ -1,11 +1,7 @@
 """Tests for certbot.plugins.dns_common_lexicon."""
 
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot.plugins import dns_common_lexicon
 from certbot.plugins import dns_test_common_lexicon
diff --git a/certbot/tests/plugins/dns_common_test.py b/certbot/tests/plugins/dns_common_test.py
--- a/certbot/tests/plugins/dns_common_test.py
+++ b/certbot/tests/plugins/dns_common_test.py
@@ -3,11 +3,7 @@
 import collections
 import logging
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors
 from certbot import util
diff --git a/certbot/tests/plugins/enhancements_test.py b/certbot/tests/plugins/enhancements_test.py
--- a/certbot/tests/plugins/enhancements_test.py
+++ b/certbot/tests/plugins/enhancements_test.py
@@ -1,10 +1,6 @@
 """Tests for new style enhancements"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot._internal.plugins import null
 from certbot.plugins import enhancements
diff --git a/certbot/tests/plugins/manual_test.py b/certbot/tests/plugins/manual_test.py
--- a/certbot/tests/plugins/manual_test.py
+++ b/certbot/tests/plugins/manual_test.py
@@ -2,11 +2,7 @@
 import sys
 import textwrap
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from acme import challenges
 from certbot import errors
diff --git a/certbot/tests/plugins/null_test.py b/certbot/tests/plugins/null_test.py
--- a/certbot/tests/plugins/null_test.py
+++ b/certbot/tests/plugins/null_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot._internal.plugins.null."""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 
 class InstallerTest(unittest.TestCase):
diff --git a/certbot/tests/plugins/selection_test.py b/certbot/tests/plugins/selection_test.py
--- a/certbot/tests/plugins/selection_test.py
+++ b/certbot/tests/plugins/selection_test.py
@@ -2,7 +2,7 @@
 import sys
 from typing import List
 import unittest
-
+from unittest import mock
 
 from certbot import errors
 from certbot import interfaces
@@ -11,11 +11,6 @@
 from certbot.display import util as display_util
 from certbot.tests import util as test_util
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
 
 class ConveniencePickPluginTest(unittest.TestCase):
     """Tests for certbot._internal.plugins.selection.pick_*."""
diff --git a/certbot/tests/plugins/standalone_test.py b/certbot/tests/plugins/standalone_test.py
--- a/certbot/tests/plugins/standalone_test.py
+++ b/certbot/tests/plugins/standalone_test.py
@@ -5,6 +5,7 @@
 from typing import Set
 from typing import Tuple
 import unittest
+from unittest import mock
 
 import josepy as jose
 import OpenSSL.crypto
@@ -16,11 +17,6 @@
 from certbot.tests import acme_util
 from certbot.tests import util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
 
 class ServerManagerTest(unittest.TestCase):
     """Tests for certbot._internal.plugins.standalone.ServerManager."""
diff --git a/certbot/tests/plugins/storage_test.py b/certbot/tests/plugins/storage_test.py
--- a/certbot/tests/plugins/storage_test.py
+++ b/certbot/tests/plugins/storage_test.py
@@ -4,17 +4,13 @@
 from typing import List
 from typing import Optional
 import unittest
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import filesystem
 from certbot.compat import os
 from certbot.tests import util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
 
 
 class PluginStorageTest(test_util.ConfigTestCase):
diff --git a/certbot/tests/plugins/util_test.py b/certbot/tests/plugins/util_test.py
--- a/certbot/tests/plugins/util_test.py
+++ b/certbot/tests/plugins/util_test.py
@@ -1,10 +1,6 @@
 """Tests for certbot.plugins.util."""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot.compat import os
 
diff --git a/certbot/tests/plugins/webroot_test.py b/certbot/tests/plugins/webroot_test.py
--- a/certbot/tests/plugins/webroot_test.py
+++ b/certbot/tests/plugins/webroot_test.py
@@ -8,12 +8,9 @@
 import shutil
 import tempfile
 import unittest
+from unittest import mock
 
 import josepy as jose
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
 
 from acme import challenges
 from certbot import achallenges
diff --git a/certbot/tests/renewal_test.py b/certbot/tests/renewal_test.py
--- a/certbot/tests/renewal_test.py
+++ b/certbot/tests/renewal_test.py
@@ -1,18 +1,13 @@
 """Tests for certbot._internal.renewal"""
 import copy
 import unittest
+from unittest import mock
 
 from acme import challenges
 from certbot import errors, configuration
 from certbot._internal import storage
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError:  # pragma: no cover
-    from unittest import mock
-
-
 
 class RenewalTest(test_util.ConfigTestCase):
     @mock.patch('certbot._internal.cli.set_by_cli')
diff --git a/certbot/tests/renewupdater_test.py b/certbot/tests/renewupdater_test.py
--- a/certbot/tests/renewupdater_test.py
+++ b/certbot/tests/renewupdater_test.py
@@ -1,10 +1,6 @@
 """Tests for renewal updater interfaces"""
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import interfaces
 from certbot._internal import main
diff --git a/certbot/tests/reverter_test.py b/certbot/tests/reverter_test.py
--- a/certbot/tests/reverter_test.py
+++ b/certbot/tests/reverter_test.py
@@ -4,11 +4,7 @@
 import shutil
 import tempfile
 import unittest
-
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import os
diff --git a/certbot/tests/storage_test.py b/certbot/tests/storage_test.py
--- a/certbot/tests/storage_test.py
+++ b/certbot/tests/storage_test.py
@@ -4,12 +4,9 @@
 import shutil
 import stat
 import unittest
+from unittest import mock
 
 import configobj
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
 import pytz
 
 import certbot
diff --git a/certbot/tests/util_test.py b/certbot/tests/util_test.py
--- a/certbot/tests/util_test.py
+++ b/certbot/tests/util_test.py
@@ -5,18 +5,13 @@
 import io
 import sys
 import unittest
+from unittest import mock
 
 from certbot import errors
 from certbot.compat import filesystem
 from certbot.compat import os
 import certbot.tests.util as test_util
 
-try:
-    import mock
-except ImportError: # pragma: no cover
-    from unittest import mock
-
-
 
 class EnvNoSnapForExternalCallsTest(unittest.TestCase):
     """Tests for certbot.util.env_no_snap_for_external_calls."""