Skip to content

Commit 7537e94

Browse files
committed
tests: use unittest.mock with py34+
Fixes pytest-dev#3965. Has to work around tox-dev/tox#706. No coverage for pluggymaster builds is OK though anyway.
1 parent 2c90b3d commit 7537e94

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ env:
1818
- TOXENV=py27-xdist
1919
- TOXENV=py27-trial
2020
- TOXENV=py27-numpy
21-
- TOXENV=py27-pluggymaster
21+
- TOXENV=py27-pluggymaster PYTEST_NO_COVERAGE=1
2222
- TOXENV=py36-pexpect
2323
- TOXENV=py36-xdist
2424
- TOXENV=py36-trial
2525
- TOXENV=py36-numpy
26-
- TOXENV=py36-pluggymaster
26+
- TOXENV=py36-pluggymaster PYTEST_NO_COVERAGE=1
2727
- TOXENV=py27-nobyte
2828
- TOXENV=doctesting
2929
- TOXENV=docs PYTEST_NO_COVERAGE=1

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ environment:
1313
- TOXENV: "py27-trial"
1414
- TOXENV: "py27-numpy"
1515
- TOXENV: "py27-pluggymaster"
16+
PYTEST_NO_COVERAGE: "1"
1617
- TOXENV: "py36-xdist"
1718
- TOXENV: "py36-trial"
1819
- TOXENV: "py36-numpy"
1920
- TOXENV: "py36-pluggymaster"
21+
PYTEST_NO_COVERAGE: "1"
2022
- TOXENV: "py27-nobyte"
2123
- TOXENV: "doctesting"
2224
- TOXENV: "py36-freeze"

testing/code/test_code.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# coding: utf-8
22
from __future__ import absolute_import, division, print_function
3+
34
import sys
45

56
import _pytest._code
67
import pytest
7-
import mock
8-
from test_excinfo import TWMock
98
from six import text_type
109

10+
from test_excinfo import TWMock
11+
12+
try:
13+
import mock
14+
except ImportError:
15+
import unittest.mock as mock
16+
1117

1218
def test_ne():
1319
code1 = _pytest._code.Code(compile('foo = "bar"', "", "exec"))

tox.ini

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ setenv =
3030
deps =
3131
hypothesis>=3.56
3232
nose
33-
mock
33+
{py27,pypy}: mock
3434
requests
3535
{env:_PYTEST_TOX_EXTRA_DEP:}
3636

3737
[testenv:py27-subprocess]
3838
changedir = .
3939
deps =
4040
pytest-xdist>=1.13
41-
mock
41+
py27: mock
4242
nose
4343
passenv = USER USERNAME TRAVIS
4444
commands =
@@ -54,7 +54,7 @@ commands = pre-commit run --all-files --show-diff-on-failure
5454
[testenv:py27-xdist]
5555
deps =
5656
pytest-xdist>=1.13
57-
mock
57+
{py27,pypy}: mock
5858
nose
5959
hypothesis>=3.56
6060
{env:_PYTEST_TOX_EXTRA_DEP:}
@@ -64,7 +64,13 @@ commands =
6464
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest -n auto -ra {posargs:testing}
6565

6666
[testenv:py36-xdist]
67-
deps = {[testenv:py27-xdist]deps}
67+
# NOTE: copied from above due to https://github.com/tox-dev/tox/issues/706.
68+
deps =
69+
pytest-xdist>=1.13
70+
{py27,pypy}: mock
71+
nose
72+
hypothesis>=3.56
73+
{env:_PYTEST_TOX_EXTRA_DEP:}
6874
commands = {[testenv:py27-xdist]commands}
6975

7076
[testenv:py27-pexpect]
@@ -87,7 +93,7 @@ commands = {[testenv:py27-pexpect]commands}
8793
deps =
8894
pytest-xdist>=1.13
8995
hypothesis>=3.56
90-
mock
96+
py27: mock
9197
{env:_PYTEST_TOX_EXTRA_DEP:}
9298
distribute = true
9399
changedir=testing
@@ -127,13 +133,11 @@ commands = {[testenv:py27-numpy]commands}
127133
setenv=
128134
{[testenv]setenv}
129135
_PYTEST_SETUP_SKIP_PLUGGY_DEP=1
130-
deps =
131-
{[testenv]deps}
132-
git+https://github.com/pytest-dev/pluggy.git@master
136+
# NOTE: using env instead of "{[testenv]deps}", because of https://github.com/tox-dev/tox/issues/706.
137+
_PYTEST_TOX_EXTRA_DEP=git+https://github.com/pytest-dev/pluggy.git@master
133138

134139
[testenv:py36-pluggymaster]
135140
setenv = {[testenv:py27-pluggymaster]setenv}
136-
deps = {[testenv:py27-pluggymaster]deps}
137141

138142
[testenv:docs]
139143
skipsdist = True

0 commit comments

Comments
 (0)