Skip to content

Commit b4993f3

Browse files
committed
BF(PY2): use mock module if no unittest.mock is available
1 parent ad59bd5 commit b4993f3

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

test_abstract_factory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
else:
1010
import unittest
1111

12-
from unittest.mock import patch
12+
try:
13+
from unittest.mock import patch
14+
except ImportError:
15+
from mock import patch
1316

1417

1518
class TestPetShop(unittest.TestCase):

test_bridge.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
else:
1010
import unittest
1111

12-
from unittest.mock import patch
12+
try:
13+
from unittest.mock import patch
14+
except ImportError:
15+
from mock import patch
16+
1317

1418
class BridgeTest(unittest.TestCase):
1519

test_hsm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
else:
88
import unittest
99

10-
from unittest.mock import patch
10+
try:
11+
from unittest.mock import patch
12+
except ImportError:
13+
from mock import patch
1114

1215

1316
class HsmMethodTest(unittest.TestCase):

test_observer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
if sys.version_info < (2, 7):
99
import unittest2 as unittest
10-
1110
else:
1211
import unittest
1312

14-
from unittest.mock import patch
13+
try:
14+
from unittest.mock import patch
15+
except ImportError:
16+
from mock import patch
17+
1518

1619
class TestSubject(unittest.TestCase):
1720

test_publish_subscribe.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
if version_info < (2, 7):
88
import unittest2 as unittest
9-
109
else:
1110
import unittest
1211

13-
from unittest.mock import patch, call
12+
try:
13+
from unittest.mock import patch, call
14+
except ImportError:
15+
from mock import patch, call
16+
1417

1518
class TestProvider(unittest.TestCase):
1619
"""

0 commit comments

Comments
 (0)