Repository: certbot/certbot (language: python)

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 / hints:

Fix patch:
diff --git a/certbot/setup.py b/certbot/setup.py
index 600087d7f27..8ea0b0e6f30 100644
--- 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',
diff --git a/tools/oldest_constraints.txt b/tools/oldest_constraints.txt
index bbbbc579ade..2e723bd8151 100644
--- a/tools/oldest_constraints.txt
+++ b/tools/oldest_constraints.txt
@@ -45,7 +45,6 @@ jsonschema==3.2.0; python_version >= "3.7"
 lazy-object-proxy==1.7.1; python_version >= "3.7"
 logger==1.4; python_version >= "3.7"
 mccabe==0.7.0; python_version >= "3.7"
-mock==1.0.1
 mypy-extensions==0.4.3; python_version >= "3.7"
 mypy==0.971; python_version >= "3.7"
 ndg-httpsclient==0.3.2
@@ -92,7 +91,6 @@ tomli==2.0.1; python_version < "3.11" and python_version >= "3.7" or python_full
 tox==1.9.2; python_version >= "3.7"
 typed-ast==1.5.4; python_version >= "3.7" and python_version < "3.8" or implementation_name == "cpython" and python_version < "3.8" and python_version >= "3.7"
 types-cryptography==3.3.21; python_version >= "3.7"
-types-mock==4.0.15; python_version >= "3.7"
 types-pyopenssl==22.0.9; python_version >= "3.7"
 types-pyrfc3339==1.1.1; python_version >= "3.7"
 types-python-dateutil==2.8.19; python_version >= "3.7"
diff --git a/tools/pinning/current/pyproject.toml b/tools/pinning/current/pyproject.toml
index eb42ecd342a..77b4fdf8d07 100644
--- a/tools/pinning/current/pyproject.toml
+++ b/tools/pinning/current/pyproject.toml
@@ -50,13 +50,6 @@ awscli = ">=1.22.76"
 # as a dependency here to ensure a version of cython is pinned for extra
 # stability.
 cython = "*"
-# We install mock in our "external-mock" tox environment to test that we didn't
-# break Certbot's test API which used to always use mock objects from the 3rd
-# party mock library. We list the mock dependency here so that is pinned, but
-# we don't depend on it in Certbot to avoid installing mock when it's not
-# needed. This dependency can be removed here once Certbot's support for the
-# 3rd party mock library has been dropped.
-mock = "*"
 # poetry 1.2.0+ is required for it to pin pip, setuptools, and wheel. See
 # https://github.com/python-poetry/poetry/issues/1584. This version is required
 # here in addition to certbot/setup.py because otherwise the pre-release
diff --git a/tools/pinning/oldest/pyproject.toml b/tools/pinning/oldest/pyproject.toml
index b6aed9dc07e..67b835551ab 100644
--- a/tools/pinning/oldest/pyproject.toml
+++ b/tools/pinning/oldest/pyproject.toml
@@ -61,7 +61,6 @@ google-api-python-client = "1.5.5"
 httplib2 = "0.9.2"
 idna = "2.6"
 ipaddress = "1.0.16"
-mock = "1.0.1"
 ndg-httpsclient = "0.3.2"
 oauth2client = "4.0.0"
 parsedatetime = "2.4"
diff --git a/tools/requirements.txt b/tools/requirements.txt
index e25e7f565b5..36b0f512893 100644
--- a/tools/requirements.txt
+++ b/tools/requirements.txt
@@ -84,7 +84,6 @@ lockfile==0.12.2
 markupsafe==2.1.1; python_version >= "3.7"
 matplotlib-inline==0.1.3; python_version >= "3.7"
 mccabe==0.7.0; python_version >= "3.7"
-mock==4.0.3
 msgpack==1.0.4; python_version >= "3.7" and python_version < "4.0"
 msrest==0.6.21; python_version >= "3.7"
 mypy-extensions==0.4.3; python_version >= "3.7"
@@ -170,7 +169,6 @@ traitlets==5.3.0; python_version >= "3.7"
 twine==3.3.0; python_version >= "3.7"
 typed-ast==1.5.4; python_version >= "3.7" and python_version < "3.8" or implementation_name == "cpython" and python_version < "3.8" and python_version >= "3.7"
 types-cryptography==3.3.21; python_version >= "3.7"
-types-mock==4.0.15; python_version >= "3.7"
 types-pyopenssl==22.0.9; python_version >= "3.7"
 types-pyrfc3339==1.1.1; python_version >= "3.7"
 types-python-dateutil==2.8.19; python_version >= "3.7"
diff --git a/tox.ini b/tox.ini
index f4776328d99..8125304f716 100644
--- a/tox.ini
+++ b/tox.ini
@@ -112,11 +112,6 @@ commands =
 setenv =
     {[testenv:oldest]setenv}
 
-[testenv:external-mock]
-commands =
-    python {toxinidir}/tools/pip_install.py mock
-    {[base]install_and_test} {[base]all_packages}
-
 [testenv:lint{,-win,-posix}]
 basepython = python3
 # separating into multiple invocations disables cross package


Test patch:
diff --git a/.azure-pipelines/templates/jobs/extended-tests-jobs.yml b/.azure-pipelines/templates/jobs/extended-tests-jobs.yml
index 7c586ee5bca..0f732e6c909 100644
--- a/.azure-pipelines/templates/jobs/extended-tests-jobs.yml
+++ b/.azure-pipelines/templates/jobs/extended-tests-jobs.yml
@@ -18,8 +18,6 @@ jobs:
           PYTHON_VERSION: 3.7
           TOXENV: py37
           CERTBOT_NO_PIN: 1
-        linux-external-mock:
-          TOXENV: external-mock
         linux-boulder-v2-integration-certbot-oldest:
           PYTHON_VERSION: 3.7
           TOXENV: integration-certbot-oldest
diff --git a/certbot-apache/tests/augeasnode_test.py b/certbot-apache/tests/augeasnode_test.py
index 1e11b5eb3f4..591634d359c 100644
--- 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
index 664d791bd78..70ed2ca1a6a 100644
--- 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
index c9a82046629..cc295266fd6 100644
--- 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
index 72b8fe2bd0d..fe0dfb39dff 100644
--- 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
index 566907506e3..0978b302e29 100644
--- 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
index 2bbf403124f..facc6510798 100644
--- 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
index 50ab6bfc723..26927ffadba 100644
--- 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
index 83a5729a55f..a3e28d09e34 100644
--- 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
index 2a269441535..0b9644f09a4 100644
--- 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
index fca3c4ba451..4ff704aafe1 100644
--- 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
index 25f9e929bd2..4df46e70f9f 100644
--- 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
index 65dfb6344b4..fe5b69b33e9 100644
--- 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
index 31a769ddd0d..89633ae4774 100644
--- 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
index ebeda3c37ba..6c153acc4f8 100644
--- 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
index a4191b3fec8..cf97d9e7a18 100644
--- 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
index 2b182783103..cd73adc8fa0 100644
--- 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
index 4683893e80e..8fdee38f37d 100644
--- 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
index fc3dc5b1f26..0e28f43b2cf 100644
--- 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
index a04716d95f1..46f5895a871 100644
--- 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
index 1310f74ca9b..b982e3e1b7a 100644
--- 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
index b6f63a937f9..27e8b1a653c 100644
--- 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
index d0d6ceb039f..c227ef4b5db 100644
--- 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
index 7592e2323bd..3c1ac68418d 100644
--- 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
index 3754f98114b..13ea09b3df8 100644
--- 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
index 7f93967eb59..7eb767b7007 100644
--- 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
index d0434aef558..1f91d3cb666 100644
--- 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
index 69b6b115d4c..bdc70e04887 100644
--- 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
index 1c64df3729b..a1abf7b783a 100644
--- 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
index a182f789a5c..916dfe3f54d 100644
--- 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
index b9917af3577..05be062029e 100644
--- 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
index 4d1f2527743..60ff1c97550 100644
--- 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
index 6cc701f42c8..1ac649318bf 100644
--- 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
index a2ab84dcb4e..65c9cc2c81d 100644
--- 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
index 01f4c6d619f..3710404046b 100644
--- 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
index dbff31a14de..0ef5f654c14 100644
--- 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
index e034c5f32f2..0037de31e74 100644
--- 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
index ba0323c3e58..23d5b2ae2e6 100644
--- 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
index 0ed09eccddb..157d45b5512 100644
--- 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
index 82138f52d59..54abe2594c5 100644
--- 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
index 70f46aee79a..6b430831f89 100644
--- 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
index 9aab49c34fa..a9a258ba290 100644
--- 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
index 2155bd5a049..5cb8167b6ba 100644
--- 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
index 1c122615bd5..61c902bc912 100644
--- 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
index 9a111a0ebf3..3031cf531f9 100644
--- 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
index a6ada8b9acd..73722151a4f 100644
--- 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
index 86489b6a51b..b29396c415b 100644
--- 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
index e00eeb08620..1235190a7f7 100644
--- 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
index 7985de753c7..7eb45653c5e 100644
--- 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
index c61f183cb11..6a8ac2c6110 100644
--- 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
index 010a756c12b..d6d506956bc 100644
--- 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
index 792868df0c2..d05f2b43ea9 100644
--- 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
index 0abe277bf54..c67211a43fa 100644
--- 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
index fad18dc9f8c..8cd8e663157 100644
--- 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
index b45eb8f7a99..1e752578208 100644
--- 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
index aec3ac65a96..855582591f8 100644
--- 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
index e26b19357bd..579682bdfbb 100644
--- 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
index c102667bc6b..802787e020d 100644
--- 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
index 46d766bcfaf..215faaea3bb 100644
--- 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
index 6b599f561db..c564cebce06 100644
--- 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
index 40afd107bac..4634c205726 100644
--- 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
index f68d36137ad..97bc5dea62a 100644
--- 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
index 62289d95bf7..903d3e0950e 100644
--- 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
index cfe2f60fa8e..a5dc69c32f3 100644
--- 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
index dfdd0a7deb7..ce3440e5bc4 100644
--- 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
index b2f38754262..6aed9ec8d22 100644
--- 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
index 2649abae929..39454570e7e 100644
--- 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
index 66034b09ec5..a63ef779566 100644
--- 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
index 1b4fcd6529f..faac0116532 100644
--- 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
index d7e96159658..d5ccc4b4f7b 100644
--- 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
index d6e2866dc56..f3968944f6f 100644
--- 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
index f086e3cf31f..30a7b0f46e7 100644
--- 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
index e8d85d4d1cd..5124c7d9f9c 100644
--- 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
index c4e42ec379f..3a1f2b7b421 100644
--- 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
index 0da0976b8eb..e9b5ddef2b2 100644
--- 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."""
diff --git a/pytest.ini b/pytest.ini
index 42853f26be1..704912685da 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -11,14 +11,12 @@
 # we release breaking changes.
 #
 # The current warnings being ignored are:
-# 1) The warning raised when importing certbot.tests.util and the external mock
-#    library is installed.
-# 2) A deprecation warning is raised in dnspython==1.15.0 in the oldest tests for
+# 1) A deprecation warning is raised in dnspython==1.15.0 in the oldest tests for
 #    certbot-dns-rfc2136.
-# 3) botocore is currently using deprecated urllib3 functionality. See
-#    https://github.com/boto/botocore/issues/2744.
+# 2) botocore's default TLS settings raise deprecation warnings in Python
+#    3.10+, but their values are sane from a security perspective. See
+#    https://github.com/boto/botocore/issues/2550.
 filterwarnings =
     error
-    ignore:The external mock module:PendingDeprecationWarning
     ignore:decodestring\(\) is a deprecated alias:DeprecationWarning:dns
     ignore:'urllib3.contrib.pyopenssl:DeprecationWarning:botocore