From ab79b3f954b694e74ae4a060258981dc3fe74026 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 27 Jan 2016 20:27:19 -0200 Subject: [PATCH 1/3] Fix pytest 2.7.X regression Fix #28 --- CHANGELOG.rst | 13 +++++++++++-- pytest_mock.py | 12 +++++++++--- setup.py | 2 +- test_pytest_mock.py | 7 +++++-- tox.ini | 8 ++++++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e017fdc..4e31021 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,12 @@ +0.10.1 +------ + +* Fix regression when using ``pytest-mock`` with ``pytest-2.7.X``. + Thanks `@akscram`_ for the report (`#28`_). + +.. _@akscram: https://github.com/Chronial +.. _#28: https://github.com/pytest-dev/pytest-mock/issues/28 + 0.10 ---- @@ -6,8 +15,8 @@ Thanks to `@Chronial`_ for idea and PR (`#26`_, `#27`_)! .. _@Chronial: https://github.com/Chronial -.. _#26: https://github.com/pytest-dev/pytest-qt/issues/26 -.. _#27: https://github.com/pytest-dev/pytest-qt/issues/27 +.. _#26: https://github.com/pytest-dev/pytest-mock/issues/26 +.. _#27: https://github.com/pytest-dev/pytest-mock/issues/27 0.9.0 ----- diff --git a/pytest_mock.py b/pytest_mock.py index cc99e0f..172028c 100644 --- a/pytest_mock.py +++ b/pytest_mock.py @@ -1,15 +1,15 @@ import inspect import sys +from distutils.util import strtobool import pytest -from distutils.util import strtobool if sys.version_info >= (3, 3): # pragma: no cover import unittest.mock as mock_module else: import mock as mock_module -version = '0.10.0' +version = '0.10.1' class MockFixture(object): """ @@ -207,7 +207,13 @@ def wrap_assert_methods(config): mock_module.NonCallableMock, method, wrapper) patcher.start() _mock_module_patches.append(patcher) - config.add_cleanup(unwrap_assert_methods) + + if hasattr(config, 'add_cleanup'): + add_cleanup = config.add_cleanup + else: + # pytest 2.7 compatibility + add_cleanup = config._cleanup.append + add_cleanup(unwrap_assert_methods) def unwrap_assert_methods(): diff --git a/setup.py b/setup.py index 4521335..aa726d0 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ py_modules=['pytest_mock'], platforms='any', install_requires=[ - 'pytest>=2.4', + 'pytest>=2.7', ], extras_require={ ':python_version=="2.6" or python_version=="2.7"': ['mock'], diff --git a/test_pytest_mock.py b/test_pytest_mock.py index d0516b2..60d2bbf 100644 --- a/test_pytest_mock.py +++ b/test_pytest_mock.py @@ -326,8 +326,11 @@ def test_foo(mocker): [pytest] mock_traceback_monkeypatch = false """) - - result = testdir.runpytest_subprocess() + if hasattr(testdir, 'runpytest_subprocess'): + result = testdir.runpytest_subprocess() + else: + # pytest 2.7.X + result = testdir.runpytest() assert result.ret == 0 diff --git a/tox.ini b/tox.ini index 37292da..ebd3dc2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,11 @@ [tox] # note that tox expects interpreters to be found at C:\PythonXY, # with XY being python version ("27" or "34") for instance -envlist = py26, py27, py34, py35 +envlist = py{26,27,34,35}-pytest{27,28} [testenv] -commands = py.test test_pytest_mock.py \ No newline at end of file +passenv = USER USERNAME +deps = + pytest27: pytest==2.7.3 + pytest28: pytest==2.8.7 +commands = py.test test_pytest_mock.py From 6a4f9fe49e9ec819c2f0044ab58035669da87e72 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 27 Jan 2016 20:36:53 -0200 Subject: [PATCH 2/3] Fix regression in frozen tests due to distutils dependency Fix #29 --- CHANGELOG.rst | 4 ++++ pytest_mock.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4e31021..cc003ce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,11 +1,15 @@ 0.10.1 ------ +* Fix regression in frozen tests due to ``distutils`` import dependency. + Thanks `@The-Compiler`_ for the report (`#29`_). + * Fix regression when using ``pytest-mock`` with ``pytest-2.7.X``. Thanks `@akscram`_ for the report (`#28`_). .. _@akscram: https://github.com/Chronial .. _#28: https://github.com/pytest-dev/pytest-mock/issues/28 +.. _#29: https://github.com/pytest-dev/pytest-mock/issues/29 0.10 ---- diff --git a/pytest_mock.py b/pytest_mock.py index 172028c..99c2ad4 100644 --- a/pytest_mock.py +++ b/pytest_mock.py @@ -1,6 +1,5 @@ import inspect import sys -from distutils.util import strtobool import pytest @@ -11,6 +10,7 @@ version = '0.10.1' + class MockFixture(object): """ Fixture that provides the same interface to functions in the mock module, @@ -233,7 +233,10 @@ def pytest_addoption(parser): def parse_ini_boolean(value): if value in (True, False): return value - return bool(strtobool(value)) + try: + return {'true': True, 'false': False}[value.lower()] + except KeyError: + raise ValueError('unknown string for bool: %r' % value) def pytest_configure(config): From 9569ca86a81461989cefe6f20b92ee8b9f6ecc14 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 27 Jan 2016 21:26:09 -0200 Subject: [PATCH 3/3] Refactor appveyor and travis to use tox --- .travis.yml | 9 ++------- appveyor.yml | 4 ++-- runtests.py | 3 --- tox.ini | 3 ++- 4 files changed, 6 insertions(+), 13 deletions(-) delete mode 100644 runtests.py diff --git a/.travis.yml b/.travis.yml index dff7eca..4f5e420 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,12 @@ language: python python: - - 2.6 - - 2.7 - - 3.4 - 3.5 - - pypy install: - - pip install coveralls --use-wheel + - pip install tox coveralls script: - - python setup.py develop - - coverage run --source=pytest_mock.py runtests.py + - tox after_success: - coveralls diff --git a/appveyor.yml b/appveyor.yml index d8b9885..31aaa37 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ install: - - C:\Python34\python -m pip install tox + - C:\Python35\python -m pip install tox build: false # Not a C# project test_script: - - C:\Python34\scripts\tox -e py27,py34,py35 + - C:\Python35\scripts\tox diff --git a/runtests.py b/runtests.py deleted file mode 100644 index 02362ad..0000000 --- a/runtests.py +++ /dev/null @@ -1,3 +0,0 @@ -# simple pytest wrapper so we can execute it using "coverage run" -import pytest, sys -sys.exit(pytest.main()) diff --git a/tox.ini b/tox.ini index ebd3dc2..dd1605a 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ envlist = py{26,27,34,35}-pytest{27,28} [testenv] passenv = USER USERNAME deps = + coverage pytest27: pytest==2.7.3 pytest28: pytest==2.8.7 -commands = py.test test_pytest_mock.py +commands = coverage run --append --source=pytest_mock.py -m pytest test_pytest_mock.py