From 239ec7102dbdf2e654855fa94e2795f3242a69d7 Mon Sep 17 00:00:00 2001 From: Peter Hamilton Date: Wed, 4 Jan 2017 11:29:30 -0500 Subject: [PATCH] Fixes how open is mocked in the server test suite This change updates how the built-in open function is mocked in the PyKMIP server test suite. On some platforms the old approach was insufficient. This change explicitly references the builtins module for Python3+, removing the old module-based mock. --- kmip/tests/unit/services/server/test_server.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kmip/tests/unit/services/server/test_server.py b/kmip/tests/unit/services/server/test_server.py index 1c3c9e0..7c686c4 100644 --- a/kmip/tests/unit/services/server/test_server.py +++ b/kmip/tests/unit/services/server/test_server.py @@ -15,7 +15,12 @@ import errno import logging -import mock + +try: + import unittest.mock as mock +except: + import mock + import signal import socket import testtools @@ -75,9 +80,11 @@ class TestKmipServer(testtools.TestCase): # Dynamically mock out the built-in open function. Approach changes # across Python versions. try: - import io # NOQA - module = 'kmip.services.server.server' - except: + # For Python3+ + import builtins # NOQA + module = 'builtins' + except ImportError: + # For Python2+ module = '__builtin__' with mock.patch('{0}.open'.format(module), open_mock):