rdobuilder 240f61
Prefer and use built-in unittest.mock in Python 3.3+ instead
rdobuilder 240f61
of unnecessarily requiring the external mock package.  This helps
rdobuilder 240f61
distributions that are phasing out Python 2 to remove redundant
rdobuilder 240f61
packages.
rdobuilder 240f61
rdobuilder 240f61
--- a/dev-requirements.txt
rdobuilder 240f61
+++ b/dev-requirements.txt
rdobuilder 240f61
@@ -4,7 +4,7 @@ invocations==2.6.0
rdobuilder 240f61
 pytest==4.4.2
rdobuilder 240f61
 # pytest-xdist for test dir watching and the inv guard task
rdobuilder 240f61
 pytest-xdist==1.28.0
rdobuilder 240f61
-mock==2.0.0
rdobuilder 240f61
+mock==2.0.0;python_version<"3.3"
rdobuilder 240f61
 # Linting!
rdobuilder 240f61
 flake8==3.8.3
rdobuilder 240f61
 # Formatting!
rdobuilder 240f61
--- a/tests/test_channelfile.py
rdobuilder 240f61
+++ b/tests/test_channelfile.py
rdobuilder 240f61
@@ -1,4 +1,7 @@
rdobuilder 240f61
-from mock import patch, MagicMock
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import patch, MagicMock
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import patch, MagicMock
rdobuilder 240f61
 
rdobuilder 240f61
 from paramiko import Channel, ChannelFile, ChannelStderrFile, ChannelStdinFile
rdobuilder 240f61
 
rdobuilder 240f61
--- a/tests/test_client.py
rdobuilder 240f61
+++ b/tests/test_client.py
rdobuilder 240f61
@@ -34,7 +34,10 @@ import weakref
rdobuilder 240f61
 from tempfile import mkstemp
rdobuilder 240f61
 
rdobuilder 240f61
 import pytest
rdobuilder 240f61
-from mock import patch, Mock
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import patch, Mock
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import patch, Mock
rdobuilder 240f61
 
rdobuilder 240f61
 import paramiko
rdobuilder 240f61
 from paramiko import SSHClient
rdobuilder 240f61
--- a/tests/test_config.py
rdobuilder 240f61
+++ b/tests/test_config.py
rdobuilder 240f61
@@ -11,7 +11,11 @@ try:
rdobuilder 240f61
 except ImportError:
rdobuilder 240f61
     Result = None
rdobuilder 240f61
 
rdobuilder 240f61
-from mock import patch
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import patch
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import patch
rdobuilder 240f61
+
rdobuilder 240f61
 from pytest import raises, mark, fixture
rdobuilder 240f61
 
rdobuilder 240f61
 from paramiko import (
rdobuilder 240f61
--- a/tests/test_kex.py
rdobuilder 240f61
+++ b/tests/test_kex.py
rdobuilder 240f61
@@ -24,7 +24,11 @@ from binascii import hexlify, unhexlify
rdobuilder 240f61
 import os
rdobuilder 240f61
 import unittest
rdobuilder 240f61
 
rdobuilder 240f61
-from mock import Mock, patch
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import Mock, patch
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import Mock, patch
rdobuilder 240f61
+
rdobuilder 240f61
 import pytest
rdobuilder 240f61
 
rdobuilder 240f61
 from cryptography.hazmat.backends import default_backend
rdobuilder 240f61
--- a/tests/test_pkey.py
rdobuilder 240f61
+++ b/tests/test_pkey.py
rdobuilder 240f61
@@ -41,7 +41,12 @@ from paramiko.common import o600
rdobuilder 240f61
 
rdobuilder 240f61
 from cryptography.exceptions import UnsupportedAlgorithm
rdobuilder 240f61
 from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateNumbers
rdobuilder 240f61
-from mock import patch, Mock
rdobuilder 240f61
+
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import patch, Mock
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import patch, Mock
rdobuilder 240f61
+
rdobuilder 240f61
 import pytest
rdobuilder 240f61
 
rdobuilder 240f61
 from .util import _support, is_low_entropy, requires_sha1_signing
rdobuilder 240f61
--- a/tests/test_proxy.py
rdobuilder 240f61
+++ b/tests/test_proxy.py
rdobuilder 240f61
@@ -1,7 +1,11 @@
rdobuilder 240f61
 import signal
rdobuilder 240f61
 import socket
rdobuilder 240f61
 
rdobuilder 240f61
-from mock import patch
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import patch
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import patch
rdobuilder 240f61
+
rdobuilder 240f61
 from pytest import raises
rdobuilder 240f61
 
rdobuilder 240f61
 from paramiko import ProxyCommand, ProxyCommandFailure
rdobuilder 240f61
--- a/tests/test_transport.py
rdobuilder 240f61
+++ b/tests/test_transport.py
rdobuilder 240f61
@@ -30,7 +30,11 @@ import time
rdobuilder 240f61
 import threading
rdobuilder 240f61
 import random
rdobuilder 240f61
 import unittest
rdobuilder 240f61
-from mock import Mock
rdobuilder 240f61
+
rdobuilder 240f61
+try:
rdobuilder 240f61
+    from unittest.mock import Mock
rdobuilder 240f61
+except ImportError:
rdobuilder 240f61
+    from mock import Mock
rdobuilder 240f61
 
rdobuilder 240f61
 from paramiko import (
rdobuilder 240f61
     AuthHandler,