tests: use unittest.mock with py34+

Fixes https://github.com/pytest-dev/pytest/issues/3965.

Has to work around https://github.com/tox-dev/tox/issues/706.

No coverage for pluggymaster builds is OK though anyway.
This commit is contained in:
Daniel Hahler 2018-09-11 18:51:05 +02:00
parent 2c90b3db9e
commit 7537e94ddf
4 changed files with 25 additions and 13 deletions

View File

@ -18,12 +18,12 @@ env:
- TOXENV=py27-xdist - TOXENV=py27-xdist
- TOXENV=py27-trial - TOXENV=py27-trial
- TOXENV=py27-numpy - TOXENV=py27-numpy
- TOXENV=py27-pluggymaster - TOXENV=py27-pluggymaster PYTEST_NO_COVERAGE=1
- TOXENV=py36-pexpect - TOXENV=py36-pexpect
- TOXENV=py36-xdist - TOXENV=py36-xdist
- TOXENV=py36-trial - TOXENV=py36-trial
- TOXENV=py36-numpy - TOXENV=py36-numpy
- TOXENV=py36-pluggymaster - TOXENV=py36-pluggymaster PYTEST_NO_COVERAGE=1
- TOXENV=py27-nobyte - TOXENV=py27-nobyte
- TOXENV=doctesting - TOXENV=doctesting
- TOXENV=docs PYTEST_NO_COVERAGE=1 - TOXENV=docs PYTEST_NO_COVERAGE=1

View File

@ -13,10 +13,12 @@ environment:
- TOXENV: "py27-trial" - TOXENV: "py27-trial"
- TOXENV: "py27-numpy" - TOXENV: "py27-numpy"
- TOXENV: "py27-pluggymaster" - TOXENV: "py27-pluggymaster"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "py36-xdist" - TOXENV: "py36-xdist"
- TOXENV: "py36-trial" - TOXENV: "py36-trial"
- TOXENV: "py36-numpy" - TOXENV: "py36-numpy"
- TOXENV: "py36-pluggymaster" - TOXENV: "py36-pluggymaster"
PYTEST_NO_COVERAGE: "1"
- TOXENV: "py27-nobyte" - TOXENV: "py27-nobyte"
- TOXENV: "doctesting" - TOXENV: "doctesting"
- TOXENV: "py36-freeze" - TOXENV: "py36-freeze"

View File

@ -1,13 +1,19 @@
# coding: utf-8 # coding: utf-8
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
import sys import sys
import _pytest._code import _pytest._code
import pytest import pytest
import mock
from test_excinfo import TWMock
from six import text_type from six import text_type
from test_excinfo import TWMock
try:
import mock
except ImportError:
import unittest.mock as mock
def test_ne(): def test_ne():
code1 = _pytest._code.Code(compile('foo = "bar"', "", "exec")) code1 = _pytest._code.Code(compile('foo = "bar"', "", "exec"))

22
tox.ini
View File

@ -30,7 +30,7 @@ setenv =
deps = deps =
hypothesis>=3.56 hypothesis>=3.56
nose nose
mock {py27,pypy}: mock
requests requests
{env:_PYTEST_TOX_EXTRA_DEP:} {env:_PYTEST_TOX_EXTRA_DEP:}
@ -38,7 +38,7 @@ deps =
changedir = . changedir = .
deps = deps =
pytest-xdist>=1.13 pytest-xdist>=1.13
mock py27: mock
nose nose
passenv = USER USERNAME TRAVIS passenv = USER USERNAME TRAVIS
commands = commands =
@ -54,7 +54,7 @@ commands = pre-commit run --all-files --show-diff-on-failure
[testenv:py27-xdist] [testenv:py27-xdist]
deps = deps =
pytest-xdist>=1.13 pytest-xdist>=1.13
mock {py27,pypy}: mock
nose nose
hypothesis>=3.56 hypothesis>=3.56
{env:_PYTEST_TOX_EXTRA_DEP:} {env:_PYTEST_TOX_EXTRA_DEP:}
@ -64,7 +64,13 @@ commands =
{env:_PYTEST_TOX_COVERAGE_RUN:} pytest -n auto -ra {posargs:testing} {env:_PYTEST_TOX_COVERAGE_RUN:} pytest -n auto -ra {posargs:testing}
[testenv:py36-xdist] [testenv:py36-xdist]
deps = {[testenv:py27-xdist]deps} # NOTE: copied from above due to https://github.com/tox-dev/tox/issues/706.
deps =
pytest-xdist>=1.13
{py27,pypy}: mock
nose
hypothesis>=3.56
{env:_PYTEST_TOX_EXTRA_DEP:}
commands = {[testenv:py27-xdist]commands} commands = {[testenv:py27-xdist]commands}
[testenv:py27-pexpect] [testenv:py27-pexpect]
@ -87,7 +93,7 @@ commands = {[testenv:py27-pexpect]commands}
deps = deps =
pytest-xdist>=1.13 pytest-xdist>=1.13
hypothesis>=3.56 hypothesis>=3.56
mock py27: mock
{env:_PYTEST_TOX_EXTRA_DEP:} {env:_PYTEST_TOX_EXTRA_DEP:}
distribute = true distribute = true
changedir=testing changedir=testing
@ -127,13 +133,11 @@ commands = {[testenv:py27-numpy]commands}
setenv= setenv=
{[testenv]setenv} {[testenv]setenv}
_PYTEST_SETUP_SKIP_PLUGGY_DEP=1 _PYTEST_SETUP_SKIP_PLUGGY_DEP=1
deps = # NOTE: using env instead of "{[testenv]deps}", because of https://github.com/tox-dev/tox/issues/706.
{[testenv]deps} _PYTEST_TOX_EXTRA_DEP=git+https://github.com/pytest-dev/pluggy.git@master
git+https://github.com/pytest-dev/pluggy.git@master
[testenv:py36-pluggymaster] [testenv:py36-pluggymaster]
setenv = {[testenv:py27-pluggymaster]setenv} setenv = {[testenv:py27-pluggymaster]setenv}
deps = {[testenv:py27-pluggymaster]deps}
[testenv:docs] [testenv:docs]
skipsdist = True skipsdist = True