From c4b556166f9371d0cbc24d50dab83325aac77a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 17 Oct 2022 14:03:14 +0200 Subject: [PATCH] Consistently use unittest.mock in tests - Some tests used unittest.mock from the standard library - Some tests used mock from PyPI - Some tests tried to import unittest.mock with a fallback to mock (the import never fails on Python 3.7+, older Pythons are not supported) --- changelog.d/3638.misc.rst | 1 + pkg_resources/tests/test_markers.py | 2 +- pkg_resources/tests/test_pkg_resources.py | 5 +---- setup.cfg | 1 - setuptools/tests/test_bdist_deprecations.py | 2 +- setuptools/tests/test_build_clib.py | 3 ++- setuptools/tests/test_easy_install.py | 2 +- setuptools/tests/test_packageindex.py | 2 +- setuptools/tests/test_register.py | 5 +---- setuptools/tests/test_upload.py | 5 +---- 10 files changed, 10 insertions(+), 18 deletions(-) create mode 100644 changelog.d/3638.misc.rst diff --git a/changelog.d/3638.misc.rst b/changelog.d/3638.misc.rst new file mode 100644 index 0000000000..54481ec015 --- /dev/null +++ b/changelog.d/3638.misc.rst @@ -0,0 +1 @@ +Drop a test dependency on the ``mock`` package, always use :external+python:py:mod:`unittest.mock` -- by :user:`hroncok` diff --git a/pkg_resources/tests/test_markers.py b/pkg_resources/tests/test_markers.py index 15a3b499a6..9306d5b348 100644 --- a/pkg_resources/tests/test_markers.py +++ b/pkg_resources/tests/test_markers.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock from pkg_resources import evaluate_marker diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 6518820e6f..684c977771 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -9,10 +9,7 @@ import distutils.dist import distutils.command.install_egg_info -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock from pkg_resources import ( DistInfoDistribution, Distribution, EggInfoDistribution, diff --git a/setup.cfg b/setup.cfg index 201c260247..6921de867f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,7 +59,6 @@ testing = pytest-perf # local - mock flake8-2020 virtualenv>=13.0.0 wheel diff --git a/setuptools/tests/test_bdist_deprecations.py b/setuptools/tests/test_bdist_deprecations.py index 1a900c6766..1b69c41858 100644 --- a/setuptools/tests/test_bdist_deprecations.py +++ b/setuptools/tests/test_bdist_deprecations.py @@ -1,7 +1,7 @@ """develop tests """ -import mock import sys +from unittest import mock import pytest diff --git a/setuptools/tests/test_build_clib.py b/setuptools/tests/test_build_clib.py index 48bea2b43d..af9e7c6dc3 100644 --- a/setuptools/tests/test_build_clib.py +++ b/setuptools/tests/test_build_clib.py @@ -1,6 +1,7 @@ +from unittest import mock + import pytest -import mock from distutils.errors import DistutilsSetupError from setuptools.command.build_clib import build_clib from setuptools.dist import Distribution diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index d102e586b4..bca86066ad 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -12,7 +12,6 @@ import distutils.errors import io import zipfile -import mock import time import re import subprocess @@ -20,6 +19,7 @@ import warnings from collections import namedtuple from pathlib import Path +from unittest import mock import pytest from jaraco import path diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py index 8e9435efef..73324aa271 100644 --- a/setuptools/tests/test_packageindex.py +++ b/setuptools/tests/test_packageindex.py @@ -5,8 +5,8 @@ import urllib.request import urllib.error import http.client +from unittest import mock -import mock import pytest import setuptools.package_index diff --git a/setuptools/tests/test_register.py b/setuptools/tests/test_register.py index 986058067b..ed85e9bbd3 100644 --- a/setuptools/tests/test_register.py +++ b/setuptools/tests/test_register.py @@ -2,10 +2,7 @@ from setuptools.dist import Distribution from setuptools.errors import RemovedCommandError -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock import pytest diff --git a/setuptools/tests/test_upload.py b/setuptools/tests/test_upload.py index 7586cb262d..4ed59bc24d 100644 --- a/setuptools/tests/test_upload.py +++ b/setuptools/tests/test_upload.py @@ -2,10 +2,7 @@ from setuptools.dist import Distribution from setuptools.errors import RemovedCommandError -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock import pytest