Skip to content

Commit 9da91c9

Browse files
authored
Merge pull request #171 from eli-schwartz/unittest-mock
use stdlib unittest.mock on python 3
2 parents a1a60d7 + 6a834d3 commit 9da91c9

File tree

20 files changed

+85
-27
lines changed

20 files changed

+85
-27
lines changed

pytest-profiling/tests/unit/test_profile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
reload_module(pytest_profiling)
99

1010
from pytest_profiling import Profiling, pytest_addoption, pytest_configure
11-
from mock import Mock, ANY, patch, sentinel
11+
12+
try:
13+
from unittest.mock import Mock, ANY, patch, sentinel
14+
except ImportError:
15+
# python 2
16+
from mock import Mock, ANY, patch, sentinel
1217

1318

1419
def test_creates_prof_dir():

pytest-server-fixtures/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
}
4444

4545
tests_require = [
46-
'mock',
46+
'mock; python_version<"3.3"',
4747
'psutil',
4848
]
4949

pytest-server-fixtures/tests/integration/test_jenkins_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import os.path
22
from pytest import raises
33

4-
from mock import patch
4+
try:
5+
from unittest.mock import patch
6+
except ImportError:
7+
# python 2
8+
from mock import patch
59

610

711
# patch out any changes you want to the Jenkins server here:

pytest-server-fixtures/tests/integration/test_xvfb_server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
from itertools import chain, repeat
66

7-
from mock import patch
7+
try:
8+
from unittest.mock import patch
9+
except ImportError:
10+
# python 2
11+
from mock import patch
12+
813
import pytest
914
from pytest import raises
1015

pytest-server-fixtures/tests/unit/serverclass/test_docker_unit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from mock import sentinel, patch, Mock
1+
try:
2+
from unittest.mock import sentinel, patch, Mock
3+
except ImportError:
4+
# python 2
5+
from mock import sentinel, patch, Mock
26

37
from pytest_server_fixtures.serverclass.docker import DockerServer
48

@@ -13,4 +17,3 @@ def test_init(mock_init):
1317
mock_init.assert_called_with(sentinel.cmd,
1418
sentinel.get_args,
1519
sentinel.env)
16-

pytest-server-fixtures/tests/unit/serverclass/test_kubernetes_unit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22

3-
from mock import sentinel, patch, Mock
3+
try:
4+
from unittest.mock import sentinel, patch, Mock
5+
except ImportError:
6+
# python 2
7+
from mock import sentinel, patch, Mock
48

59
from pytest_server_fixtures.serverclass.kubernetes import KubernetesServer
610

@@ -16,4 +20,3 @@ def test_init(mock_init):
1620
mock_init.assert_called_with(sentinel.cmd,
1721
sentinel.get_args,
1822
sentinel.env)
19-

pytest-server-fixtures/tests/unit/serverclass/test_thread_unit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from mock import sentinel, patch, Mock
1+
try:
2+
from unittest.mock import sentinel, patch, Mock
3+
except ImportError:
4+
# python 2
5+
from mock import sentinel, patch, Mock
26

37
from pytest_server_fixtures import CONFIG
48
from pytest_server_fixtures.serverclass.thread import ThreadServer
@@ -19,4 +23,3 @@ def test_init(mock_init):
1923
assert ts._hostname == sentinel.listen_hostname
2024
assert ts._workspace == sentinel.workspace
2125
assert ts._cwd == sentinel.cwd
22-

pytest-server-fixtures/tests/unit/test_server_unit.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from mock import create_autospec, sentinel, call, patch, Mock
1+
try:
2+
from unittest.mock import create_autospec, sentinel, call, patch, Mock
3+
except ImportError:
4+
# python 2
5+
from mock import create_autospec, sentinel, call, patch, Mock
26

37
from pytest_server_fixtures.base import TestServer as _TestServer # So that pytest doesnt think this is a test case
48

pytest-server-fixtures/tests/unit/test_server_v2_unit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from mock import create_autospec, sentinel, call, patch, Mock
1+
try:
2+
from unittest.mock import create_autospec, sentinel, call, patch, Mock
3+
except ImportError:
4+
# python 2
5+
from mock import create_autospec, sentinel, call, patch, Mock
26

37
from pytest_server_fixtures.base2 import TestServerV2 as _TestServerV2 # TODO: why as _TestServerV2?
48

@@ -15,4 +19,3 @@ def test_init():
1519
def test_hostname_when_server_is_not_started():
1620
ts = _TestServerV2()
1721
assert ts.hostname == None
18-

pytest-shutil/pytest_shutil/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from contextlib import closing
1212
import subprocess
1313

14-
from mock import patch
14+
try:
15+
from unittest.mock import patch
16+
except ImportError:
17+
# python 2
18+
from mock import patch
19+
1520
import execnet
1621
from six.moves import cPickle # @UnresolvedImport
1722

0 commit comments

Comments
 (0)