Hello community, here is the log from the commit of package python-pytest-mock for openSUSE:Factory checked in at 2020-05-01 11:06:02 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pytest-mock (Old) and /work/SRC/openSUSE:Factory/.python-pytest-mock.new.2738 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pytest-mock" Fri May 1 11:06:02 2020 rev:18 rq:798138 version:3.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pytest-mock/python-pytest-mock.changes 2020-01-16 18:13:42.940719412 +0100 +++ /work/SRC/openSUSE:Factory/.python-pytest-mock.new.2738/python-pytest-mock.changes 2020-05-01 11:06:13.302916900 +0200 @@ -1,0 +2,8 @@ +Mon Apr 27 10:19:49 UTC 2020 - Tomáš Chvátal <[email protected]> + +- Update to 3.1.0: + * Python 2.7 and 3.4 are no longer supported + * New mocker fixtures added that allow using mocking functionality + in other scopes + +------------------------------------------------------------------- Old: ---- pytest-mock-2.0.0.tar.gz New: ---- pytest-mock-3.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pytest-mock.spec ++++++ --- /var/tmp/diff_new_pack.6CeADq/_old 2020-05-01 11:06:14.686919910 +0200 +++ /var/tmp/diff_new_pack.6CeADq/_new 2020-05-01 11:06:14.690919918 +0200 @@ -16,11 +16,10 @@ # -%define oldpython python %{?!python_module:%define python_module() python-%{**} python3-%{**}} -%bcond_without python2 +%define skip_python2 1 Name: python-pytest-mock -Version: 2.0.0 +Version: 3.1.0 Release: 0 Summary: Thin-wrapper around the mock package for easier use with pytest License: MIT @@ -33,12 +32,6 @@ BuildRequires: python-rpm-macros Requires: python-pytest BuildArch: noarch -%if %{with python2} -BuildRequires: %{oldpython}-mock -%endif -%ifpython2 -Requires: %{oldpython}-mock -%endif %python_subpackages %description ++++++ pytest-mock-2.0.0.tar.gz -> pytest-mock-3.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/.github/workflows/main.yml new/pytest-mock-3.1.0/.github/workflows/main.yml --- old/pytest-mock-2.0.0/.github/workflows/main.yml 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/.github/workflows/main.yml 2020-04-18 17:16:30.000000000 +0200 @@ -10,11 +10,9 @@ strategy: fail-fast: false matrix: - python: ["2.7", "3.5", "3.6", "3.7", "3.8"] + python: ["3.5", "3.6", "3.7", "3.8"] os: [ubuntu-latest, windows-latest] include: - - python: "2.7" - tox_env: "py27" - python: "3.5" tox_env: "py35" - python: "3.6" @@ -58,11 +56,12 @@ deploy: + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') + runs-on: ubuntu-latest needs: [build, linting] - steps: - uses: actions/checkout@v1 - name: Set up Python @@ -77,7 +76,6 @@ run: | python setup.py sdist bdist_wheel - name: Publish package to PyPI - if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@master with: user: __token__ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/.pre-commit-config.yaml new/pytest-mock-3.1.0/.pre-commit-config.yaml --- old/pytest-mock-2.0.0/.pre-commit-config.yaml 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/.pre-commit-config.yaml 2020-04-18 17:16:30.000000000 +0200 @@ -1,13 +1,12 @@ exclude: '^($|.*\.bin)' repos: - repo: https://github.com/ambv/black - rev: 18.6b4 + rev: 19.10b0 hooks: - id: black args: [--safe, --quiet] - language_version: python3.6 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v1.3.0 + rev: v2.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/CHANGELOG.rst new/pytest-mock-3.1.0/CHANGELOG.rst --- old/pytest-mock-2.0.0/CHANGELOG.rst 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/CHANGELOG.rst 2020-04-18 17:16:30.000000000 +0200 @@ -1,3 +1,29 @@ +3.1.0 (2020-04-18) +------------------ + +* New mocker fixtures added that allow using mocking functionality in other scopes: + + * ``class_mocker`` + * ``module_mocker`` + * ``package_mocker`` + * ``session_mocker`` + + Added by `@scorphus`_ in `#182`_. + +.. _@scorphus: https://github.com/scorphus +.. _#182: https://github.com/pytest-dev/pytest-mock/pull/182 + +3.0.0 (2020-03-31) +------------------ + +* Python 2.7 and 3.4 are no longer supported. Users using ``pip 9`` or later will install + a compatible version automatically. + +* ``mocker.spy`` now also works with ``async def`` functions (`#179`_). Thanks `@frankie567`_ for the PR! + +.. _#179: https://github.com/pytest-dev/pytest-mock/issues/179 +.. _@frankie567: https://github.com/frankie567 + 2.0.0 (2020-01-04) ------------------ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/PKG-INFO new/pytest-mock-3.1.0/PKG-INFO --- old/pytest-mock-2.0.0/PKG-INFO 2020-01-04 19:44:56.000000000 +0100 +++ new/pytest-mock-3.1.0/PKG-INFO 2020-04-18 17:16:34.000000000 +0200 @@ -1,7 +1,7 @@ Metadata-Version: 2.1 Name: pytest-mock -Version: 2.0.0 -Summary: Thin-wrapper around the mock package for easier use with py.test +Version: 3.1.0 +Summary: Thin-wrapper around the mock package for easier use with pytest Home-page: https://github.com/pytest-dev/pytest-mock/ Author: Bruno Oliveira Author-email: [email protected] @@ -90,6 +90,13 @@ * `sentinel <https://docs.python.org/3/library/unittest.mock.html#sentinel>`_ *(Version 1.2)* * `mock_open <https://docs.python.org/3/library/unittest.mock.html#mock-open>`_ + It is also possible to use mocking functionality from fixtures of other scopes using + the appropriate mock fixture: + + * ``class_mocker`` + * ``module_mocker`` + * ``package_mocker`` + * ``session_mocker`` Spy --- @@ -122,6 +129,8 @@ ``mocker.spy`` also works for class and static methods. + As of version 3.0.0, ``mocker.spy`` also works with ``async def`` functions. + .. note:: In versions earlier than ``2.0``, the attributes were called ``return_value`` and @@ -157,7 +166,7 @@ It also adds introspection information on differing call arguments when calling the helper methods. This features catches `AssertionError` raised in - the method, and uses py.test's own `advanced assertions`_ to return a better + the method, and uses pytest's own `advanced assertions`_ to return a better diff:: @@ -243,9 +252,8 @@ Requirements ============ - * Python 2.7, Python 3.4+ + * Python Python 3.5+ * pytest - * mock (for Python 2) Install @@ -357,7 +365,7 @@ .. code-block:: console - $ tox -e py27,py36,linting + $ tox -e py38,linting Style checks and formatting are done automatically during commit courtesy of `pre-commit <https://pre-commit.com>`_. @@ -381,14 +389,12 @@ Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3 :: Only Classifier: Topic :: Software Development :: Testing -Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* +Requires-Python: >=3.5 Provides-Extra: dev diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/README.rst new/pytest-mock-3.1.0/README.rst --- old/pytest-mock-2.0.0/README.rst 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/README.rst 2020-04-18 17:16:30.000000000 +0200 @@ -82,6 +82,13 @@ * `sentinel <https://docs.python.org/3/library/unittest.mock.html#sentinel>`_ *(Version 1.2)* * `mock_open <https://docs.python.org/3/library/unittest.mock.html#mock-open>`_ +It is also possible to use mocking functionality from fixtures of other scopes using +the appropriate mock fixture: + +* ``class_mocker`` +* ``module_mocker`` +* ``package_mocker`` +* ``session_mocker`` Spy --- @@ -114,6 +121,8 @@ ``mocker.spy`` also works for class and static methods. +As of version 3.0.0, ``mocker.spy`` also works with ``async def`` functions. + .. note:: In versions earlier than ``2.0``, the attributes were called ``return_value`` and @@ -149,7 +158,7 @@ It also adds introspection information on differing call arguments when calling the helper methods. This features catches `AssertionError` raised in -the method, and uses py.test's own `advanced assertions`_ to return a better +the method, and uses pytest's own `advanced assertions`_ to return a better diff:: @@ -235,9 +244,8 @@ Requirements ============ -* Python 2.7, Python 3.4+ +* Python Python 3.5+ * pytest -* mock (for Python 2) Install @@ -349,7 +357,7 @@ .. code-block:: console - $ tox -e py27,py36,linting + $ tox -e py38,linting Style checks and formatting are done automatically during commit courtesy of `pre-commit <https://pre-commit.com>`_. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/setup.py new/pytest-mock-3.1.0/setup.py --- old/pytest-mock-2.0.0/setup.py 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/setup.py 2020-04-18 17:16:30.000000000 +0200 @@ -8,32 +8,30 @@ packages=find_packages(where="src"), package_dir={"": "src"}, platforms="any", - python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", - install_requires=["pytest>=2.7", 'mock;python_version<"3.0"'], + python_requires=">=3.5", + install_requires=["pytest>=2.7"], use_scm_version={"write_to": "src/pytest_mock/_version.py"}, setup_requires=["setuptools_scm"], url="https://github.com/pytest-dev/pytest-mock/", license="MIT", author="Bruno Oliveira", author_email="[email protected]", - description="Thin-wrapper around the mock package for easier use with py.test", + description="Thin-wrapper around the mock package for easier use with pytest", long_description=open("README.rst", encoding="utf-8").read(), keywords="pytest mock", - extras_require={"dev": ["pre-commit", "tox"]}, + extras_require={"dev": ["pre-commit", "tox", "pytest-asyncio"]}, classifiers=[ "Development Status :: 5 - Production/Stable", "Framework :: Pytest", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Testing", ], ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/src/pytest_mock/_version.py new/pytest-mock-3.1.0/src/pytest_mock/_version.py --- old/pytest-mock-2.0.0/src/pytest_mock/_version.py 2020-01-04 19:44:55.000000000 +0100 +++ new/pytest-mock-3.1.0/src/pytest_mock/_version.py 2020-04-18 17:16:33.000000000 +0200 @@ -1,4 +1,4 @@ # coding: utf-8 # file generated by setuptools_scm # don't change, don't track in version control -version = '2.0.0' +version = '3.1.0' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/src/pytest_mock/plugin.py new/pytest-mock-3.1.0/src/pytest_mock/plugin.py --- old/pytest-mock-2.0.0/src/pytest_mock/plugin.py 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/src/pytest_mock/plugin.py 2020-04-18 17:16:30.000000000 +0200 @@ -1,8 +1,6 @@ -from __future__ import unicode_literals - +import asyncio import functools import inspect -import sys import pytest @@ -10,24 +8,18 @@ __version__ = version -# pseudo-six; if this starts to require more than this, depend on six already -if sys.version_info[0] == 2: # pragma: no cover - text_type = unicode # noqa -else: - text_type = str - def _get_mock_module(config): """ - Import and return the actual "mock" module. By default this is "mock" for Python 2 and - "unittest.mock" for Python 3, but the user can force to always use "mock" on Python 3 using + Import and return the actual "mock" module. By default this is + "unittest.mock", but the user can force to always use "mock" using the mock_use_standalone_module ini option. """ if not hasattr(_get_mock_module, "_module"): use_standalone_module = parse_ini_boolean( config.getini("mock_use_standalone_module") ) - if sys.version_info[0] == 2 or use_standalone_module: + if use_standalone_module: import mock _get_mock_module._module = mock @@ -39,7 +31,7 @@ return _get_mock_module._module -class MockFixture(object): +class MockFixture: """ Fixture that provides the same interface to functions in the mock module, ensuring that they are uninstalled at the end of each test. @@ -105,13 +97,6 @@ if isinstance(value, (classmethod, staticmethod)): autospec = False - if sys.version_info[0] == 2: - assigned = [x for x in functools.WRAPPER_ASSIGNMENTS if hasattr(method, x)] - w = functools.wraps(method, assigned=assigned) - else: - w = functools.wraps(method) - - @w def wrapper(*args, **kwargs): spy_obj.spy_return = None spy_obj.spy_exception = None @@ -124,7 +109,24 @@ spy_obj.spy_return = r return r - spy_obj = self.patch.object(obj, name, side_effect=wrapper, autospec=autospec) + async def async_wrapper(*args, **kwargs): + spy_obj.spy_return = None + spy_obj.spy_exception = None + try: + r = await method(*args, **kwargs) + except Exception as e: + spy_obj.spy_exception = e + raise + else: + spy_obj.spy_return = r + return r + + if asyncio.iscoroutinefunction(method): + wrapped = functools.update_wrapper(async_wrapper, method) + else: + wrapped = functools.update_wrapper(wrapper, method) + + spy_obj = self.patch.object(obj, name, side_effect=wrapped, autospec=autospec) spy_obj.spy_return = None spy_obj.spy_exception = None return spy_obj @@ -140,7 +142,7 @@ """ return self.mock_module.MagicMock(spec=lambda *args, **kwargs: None, name=name) - class _Patcher(object): + class _Patcher: """ Object to provide the same interface as mock.patch, mock.patch.object, etc. We need this indirection to keep the same API of the mock package. @@ -197,8 +199,7 @@ return self._start_patch(self.mock_module.patch, *args, **kwargs) [email protected]_fixture -def mocker(pytestconfig): +def _mocker(pytestconfig): """ return an object that has the same interface to the `mock` module, but takes care of automatically undoing all patches after each test method. @@ -208,6 +209,13 @@ result.stopall() +mocker = pytest.yield_fixture()(_mocker) # default scope is function +class_mocker = pytest.yield_fixture(scope="class")(_mocker) +module_mocker = pytest.yield_fixture(scope="module")(_mocker) +package_mocker = pytest.yield_fixture(scope="package")(_mocker) +session_mocker = pytest.yield_fixture(scope="session")(_mocker) + + _mock_module_patches = [] _mock_module_originals = {} @@ -219,21 +227,21 @@ return except AssertionError as e: if getattr(e, "_mock_introspection_applied", 0): - msg = text_type(e) + msg = str(e) else: __mock_self = args[0] - msg = text_type(e) + msg = str(e) if __mock_self.call_args is not None: actual_args, actual_kwargs = __mock_self.call_args introspection = "" try: assert actual_args == args[1:] except AssertionError as e: - introspection += "\nArgs:\n" + text_type(e) + introspection += "\nArgs:\n" + str(e) try: assert actual_kwargs == kwargs except AssertionError as e: - introspection += "\nKwargs:\n" + text_type(e) + introspection += "\nKwargs:\n" + str(e) if introspection: msg += "\n\npytest introspection follows:\n" + introspection @@ -324,7 +332,7 @@ # so we need to catch this error here and ignore it; # unfortunately there's no public API to check if a patch # has been started, so catching the error it is - if text_type(e) == "stop called on unstarted patcher": + if str(e) == "stop called on unstarted patcher": pass else: raise diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/src/pytest_mock.egg-info/PKG-INFO new/pytest-mock-3.1.0/src/pytest_mock.egg-info/PKG-INFO --- old/pytest-mock-2.0.0/src/pytest_mock.egg-info/PKG-INFO 2020-01-04 19:44:55.000000000 +0100 +++ new/pytest-mock-3.1.0/src/pytest_mock.egg-info/PKG-INFO 2020-04-18 17:16:33.000000000 +0200 @@ -1,7 +1,7 @@ Metadata-Version: 2.1 Name: pytest-mock -Version: 2.0.0 -Summary: Thin-wrapper around the mock package for easier use with py.test +Version: 3.1.0 +Summary: Thin-wrapper around the mock package for easier use with pytest Home-page: https://github.com/pytest-dev/pytest-mock/ Author: Bruno Oliveira Author-email: [email protected] @@ -90,6 +90,13 @@ * `sentinel <https://docs.python.org/3/library/unittest.mock.html#sentinel>`_ *(Version 1.2)* * `mock_open <https://docs.python.org/3/library/unittest.mock.html#mock-open>`_ + It is also possible to use mocking functionality from fixtures of other scopes using + the appropriate mock fixture: + + * ``class_mocker`` + * ``module_mocker`` + * ``package_mocker`` + * ``session_mocker`` Spy --- @@ -122,6 +129,8 @@ ``mocker.spy`` also works for class and static methods. + As of version 3.0.0, ``mocker.spy`` also works with ``async def`` functions. + .. note:: In versions earlier than ``2.0``, the attributes were called ``return_value`` and @@ -157,7 +166,7 @@ It also adds introspection information on differing call arguments when calling the helper methods. This features catches `AssertionError` raised in - the method, and uses py.test's own `advanced assertions`_ to return a better + the method, and uses pytest's own `advanced assertions`_ to return a better diff:: @@ -243,9 +252,8 @@ Requirements ============ - * Python 2.7, Python 3.4+ + * Python Python 3.5+ * pytest - * mock (for Python 2) Install @@ -357,7 +365,7 @@ .. code-block:: console - $ tox -e py27,py36,linting + $ tox -e py38,linting Style checks and formatting are done automatically during commit courtesy of `pre-commit <https://pre-commit.com>`_. @@ -381,14 +389,12 @@ Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3 :: Only Classifier: Topic :: Software Development :: Testing -Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.* +Requires-Python: >=3.5 Provides-Extra: dev diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/src/pytest_mock.egg-info/requires.txt new/pytest-mock-3.1.0/src/pytest_mock.egg-info/requires.txt --- old/pytest-mock-2.0.0/src/pytest_mock.egg-info/requires.txt 2020-01-04 19:44:55.000000000 +0100 +++ new/pytest-mock-3.1.0/src/pytest_mock.egg-info/requires.txt 2020-04-18 17:16:33.000000000 +0200 @@ -1,8 +1,6 @@ pytest>=2.7 -[:python_version < "3.0"] -mock - [dev] pre-commit tox +pytest-asyncio diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/tests/test_pytest_mock.py new/pytest-mock-3.1.0/tests/test_pytest_mock.py --- old/pytest-mock-2.0.0/tests/test_pytest_mock.py 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/tests/test_pytest_mock.py 2020-04-18 17:16:30.000000000 +0200 @@ -14,7 +14,7 @@ ) # Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0 -NEW_FORMATTING = sys.version_info >= (3, 8) or sys.version_info[0] == 2 +NEW_FORMATTING = sys.version_info >= (3, 8) @pytest.fixture @@ -32,7 +32,7 @@ ) -class UnixFS(object): +class UnixFS: """ Wrapper to os functions to simulate a Unix file system, used for testing the mock fixture. @@ -183,7 +183,7 @@ def test_repr_with_name(self, mocker): test_name = "funny walk" stub = mocker.stub(name=test_name) - assert "name={0!r}".format(test_name) in repr(stub) + assert "name={!r}".format(test_name) in repr(stub) def __test_failure_message(self, mocker, **kwargs): expected_name = kwargs.get("name") or "mock" @@ -206,7 +206,7 @@ def test_instance_method_spy(mocker): - class Foo(object): + class Foo: def bar(self, arg): return arg * 2 @@ -222,7 +222,7 @@ def test_instance_method_spy_exception(mocker): - class Foo(object): + class Foo: def bar(self, arg): raise Exception("Error with {}".format(arg)) @@ -266,7 +266,7 @@ @skip_pypy def test_instance_method_by_class_spy(mocker): - class Foo(object): + class Foo: def bar(self, arg): return arg * 2 @@ -281,7 +281,7 @@ @skip_pypy def test_instance_method_by_subclass_spy(mocker): - class Base(object): + class Base: def bar(self, arg): return arg * 2 @@ -300,7 +300,7 @@ @skip_pypy def test_class_method_spy(mocker): - class Foo(object): + class Foo: @classmethod def bar(cls, arg): return arg * 2 @@ -314,9 +314,8 @@ @skip_pypy [email protected](sys.version_info[0] == 2, reason="does not work on Python 2") def test_class_method_subclass_spy(mocker): - class Base(object): + class Base: @classmethod def bar(self, arg): return arg * 2 @@ -337,7 +336,7 @@ class MetaFoo(type): pass - class Foo(object): + class Foo: __metaclass__ = MetaFoo @@ -355,7 +354,7 @@ @skip_pypy def test_static_method_spy(mocker): - class Foo(object): + class Foo: @staticmethod def bar(arg): return arg * 2 @@ -369,9 +368,8 @@ @skip_pypy [email protected](sys.version_info[0] == 2, reason="does not work on Python 2") def test_static_method_subclass_spy(mocker): - class Base(object): + class Base: @staticmethod def bar(arg): return arg * 2 @@ -407,6 +405,21 @@ assert spy.spy_return == 20 [email protected] +async def test_instance_async_method_spy(mocker): + class Foo: + async def bar(self, arg): + return arg * 2 + + foo = Foo() + spy = mocker.spy(foo, "bar") + + result = await foo.bar(10) + + spy.assert_called_once_with(10) + assert result == 20 + + @contextmanager def assert_traceback(): """ @@ -442,10 +455,6 @@ raise AssertionError("DID NOT RAISE") [email protected]( - sys.version_info[:2] == (3, 4), - reason="assert_not_called not available in Python 3.4", -) def test_assert_not_called_wrapper(mocker): stub = mocker.stub() stub.assert_not_called() @@ -498,8 +507,8 @@ def test_assert_called_args_with_introspection(mocker): stub = mocker.stub() - complex_args = ("a", 1, set(["test"])) - wrong_args = ("b", 2, set(["jest"])) + complex_args = ("a", 1, {"test"}) + wrong_args = ("b", 2, {"jest"}) stub(*complex_args) stub.assert_called_with(*complex_args) @@ -631,7 +640,6 @@ assert result.stdout.lines == [] [email protected](sys.version_info[0] < 3, reason="Py3 only") def test_standalone_mock(testdir): """Check that the "mock_use_standalone" is being used. """ @@ -720,7 +728,7 @@ stub(b"l\xc3\xb6k".decode("UTF-8")) with pytest.raises(AssertionError): - stub.assert_called_with(u"lak") + stub.assert_called_with("lak") def test_plain_stopall(testdir): @@ -745,7 +753,7 @@ def test_abort_patch_object_context_manager(mocker): - class A(object): + class A: def doIt(self): return False @@ -753,7 +761,7 @@ with pytest.raises(ValueError) as excinfo: with mocker.patch.object(a, "doIt", return_value=True): - assert a.doIt() == True + assert a.doIt() is True expected_error_msg = ( "Using mocker in a with context is not supported. " @@ -803,7 +811,7 @@ result = testdir.runpytest() result.stdout.fnmatch_lines("* 1 passed *") - kwargs = {"legacy": True} if sys.version_info[0] >= 3 else {} + kwargs = {"legacy": True} assert compileall.compile_file(str(py_fn), **kwargs) pyc_fn = str(py_fn) + "c" @@ -812,3 +820,97 @@ py_fn.remove() result = testdir.runpytest() result.stdout.fnmatch_lines("* 1 passed *") + + +def test_used_with_class_scope(testdir): + """...""" + testdir.makepyfile( + """ + import pytest + import random + import unittest + + def get_random_number(): + return random.randint(0, 1) + + @pytest.fixture(autouse=True, scope="class") + def randint_mock(class_mocker): + return class_mocker.patch("random.randint", lambda x, y: 5) + + class TestGetRandomNumber(unittest.TestCase): + def test_get_random_number(self): + assert get_random_number() == 5 + """ + ) + result = testdir.runpytest_subprocess() + assert "AssertionError" not in result.stderr.str() + result.stdout.fnmatch_lines("* 1 passed in *") + + +def test_used_with_module_scope(testdir): + """...""" + testdir.makepyfile( + """ + import pytest + import random + + def get_random_number(): + return random.randint(0, 1) + + @pytest.fixture(autouse=True, scope="module") + def randint_mock(module_mocker): + return module_mocker.patch("random.randint", lambda x, y: 5) + + def test_get_random_number(): + assert get_random_number() == 5 + """ + ) + result = testdir.runpytest_subprocess() + assert "AssertionError" not in result.stderr.str() + result.stdout.fnmatch_lines("* 1 passed in *") + + +def test_used_with_package_scope(testdir): + """...""" + testdir.makepyfile( + """ + import pytest + import random + + def get_random_number(): + return random.randint(0, 1) + + @pytest.fixture(autouse=True, scope="package") + def randint_mock(package_mocker): + return package_mocker.patch("random.randint", lambda x, y: 5) + + def test_get_random_number(): + assert get_random_number() == 5 + """ + ) + result = testdir.runpytest_subprocess() + assert "AssertionError" not in result.stderr.str() + result.stdout.fnmatch_lines("* 1 passed in *") + + +def test_used_with_session_scope(testdir): + """...""" + testdir.makepyfile( + """ + import pytest + import random + + def get_random_number(): + return random.randint(0, 1) + + @pytest.fixture(autouse=True, scope="session") + def randint_mock(session_mocker): + return session_mocker.patch("random.randint", lambda x, y: 5) + + def test_get_random_number(): + assert get_random_number() == 5 + """ + ) + result = testdir.runpytest_subprocess() + assert "AssertionError" not in result.stderr.str() + result.stdout.fnmatch_lines("* 1 passed in *") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pytest-mock-2.0.0/tox.ini new/pytest-mock-3.1.0/tox.ini --- old/pytest-mock-2.0.0/tox.ini 2020-01-04 19:44:53.000000000 +0100 +++ new/pytest-mock-3.1.0/tox.ini 2020-04-18 17:16:30.000000000 +0200 @@ -1,10 +1,11 @@ [tox] -envlist = py{27,34,35,36,37,38}, linting, norewrite +envlist = py{35,36,37,38}, linting, norewrite [testenv] passenv = USER USERNAME deps = coverage + pytest-asyncio commands = coverage run --append --source={envsitepackagesdir}/pytest_mock -m pytest tests
