mirror of https://github.com/OpenKMIP/PyKMIP.git
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.
This commit is contained in:
parent
6374f914a0
commit
239ec7102d
|
@ -15,7 +15,12 @@
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import mock
|
|
||||||
|
try:
|
||||||
|
import unittest.mock as mock
|
||||||
|
except:
|
||||||
|
import mock
|
||||||
|
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import testtools
|
import testtools
|
||||||
|
@ -75,9 +80,11 @@ class TestKmipServer(testtools.TestCase):
|
||||||
# Dynamically mock out the built-in open function. Approach changes
|
# Dynamically mock out the built-in open function. Approach changes
|
||||||
# across Python versions.
|
# across Python versions.
|
||||||
try:
|
try:
|
||||||
import io # NOQA
|
# For Python3+
|
||||||
module = 'kmip.services.server.server'
|
import builtins # NOQA
|
||||||
except:
|
module = 'builtins'
|
||||||
|
except ImportError:
|
||||||
|
# For Python2+
|
||||||
module = '__builtin__'
|
module = '__builtin__'
|
||||||
|
|
||||||
with mock.patch('{0}.open'.format(module), open_mock):
|
with mock.patch('{0}.open'.format(module), open_mock):
|
||||||
|
|
Loading…
Reference in New Issue