From 4f56ff9e2beb2048c5375b18a883f9145812fe7a Mon Sep 17 00:00:00 2001 From: Michel Lind Date: Thu, 22 Feb 2024 13:26:20 -0600 Subject: [PATCH] Use deprecated mock only on Python 2.7 `unittest.mock` has been part of the Python standard library since Python 3.3. Only install the old `mock` in the `py2.7` tox target, and edit the test file to prefer `unittest.mock` and fall back to `mock` as Python 2.7 has been EOL since January 1, 2020 anyway: https://www.python.org/doc/sunset-python-2/ Signed-off-by: Michel Lind --- setup.py | 9 ++++++++- tests/ratelimitingfilter_test.py | 5 ++++- tox.ini | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index b734590..93c1927 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,11 @@ from setuptools import setup +from sys import version_info + +if version_info.major < 3 or \ + (version_info.major == 3 and version_info.minor < 4): + tests_require=['mock'] +else: + tests_require=[] setup( author='Will Keeling', @@ -26,7 +33,7 @@ name='ratelimitingfilter', packages=['ratelimitingfilter'], test_suite='tests', - tests_require=['mock'], + tests_require=tests_require, url='https://github.com/wkeeling/ratelimitingfilter', version='1.5', ) diff --git a/tests/ratelimitingfilter_test.py b/tests/ratelimitingfilter_test.py index 6235243..f874469 100644 --- a/tests/ratelimitingfilter_test.py +++ b/tests/ratelimitingfilter_test.py @@ -3,7 +3,10 @@ import logging import os from unittest.case import TestCase -from mock import Mock, patch +try: + from unittest.mock import Mock, patch +except ImportError: + from mock import Mock, patch from ratelimitingfilter import RateLimitingFilter diff --git a/tox.ini b/tox.ini index 30895d3..ee1a8b4 100644 --- a/tox.ini +++ b/tox.ini @@ -7,5 +7,5 @@ setenv = deps = coverage nose - mock + py27: mock commands = nosetests --with-coverage --cover-erase tests