Hello community,

here is the log from the commit of package python-pytest-mock for 
openSUSE:Factory checked in at 2020-06-11 14:45:28
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pytest-mock (Old)
 and      /work/SRC/openSUSE:Factory/.python-pytest-mock.new.3606 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-pytest-mock"

Thu Jun 11 14:45:28 2020 rev:19 rq:812814 version:3.1.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/python-pytest-mock/python-pytest-mock.changes    
2020-05-01 11:06:13.302916900 +0200
+++ 
/work/SRC/openSUSE:Factory/.python-pytest-mock.new.3606/python-pytest-mock.changes
  2020-06-11 14:45:56.301598607 +0200
@@ -1,0 +2,7 @@
+Tue Jun  9 07:58:45 UTC 2020 - Tomáš Chvátal <tchva...@suse.com>
+
+- Update to 3.1.1:
+  * Fixed performance regression caused by the ValueError raised
+    when mocker is used as context manager (#191).
+
+-------------------------------------------------------------------

Old:
----
  pytest-mock-3.1.0.tar.gz

New:
----
  pytest-mock-3.1.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-pytest-mock.spec ++++++
--- /var/tmp/diff_new_pack.qmhJpo/_old  2020-06-11 14:45:57.401601811 +0200
+++ /var/tmp/diff_new_pack.qmhJpo/_new  2020-06-11 14:45:57.405601822 +0200
@@ -19,7 +19,7 @@
 %{?!python_module:%define python_module() python-%{**} python3-%{**}}
 %define skip_python2 1
 Name:           python-pytest-mock
-Version:        3.1.0
+Version:        3.1.1
 Release:        0
 Summary:        Thin-wrapper around the mock package for easier use with pytest
 License:        MIT
@@ -51,9 +51,7 @@
 %python_expand %fdupes %{buildroot}%{$python_sitelib}
 
 %check
-export PYTHONDONTWRITEBYTECODE=1
-# disable current failing tests
-%pytest -k 'not test_assert_called_args_with_introspection and not 
test_assert_called_kwargs_with_introspection and not 
test_detailed_introspection'
+%pytest
 
 %files %{python_files}
 %doc CHANGELOG.rst

++++++ pytest-mock-3.1.0.tar.gz -> pytest-mock-3.1.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/.pre-commit-config.yaml 
new/pytest-mock-3.1.1/.pre-commit-config.yaml
--- old/pytest-mock-3.1.0/.pre-commit-config.yaml       2020-04-18 
17:16:30.000000000 +0200
+++ new/pytest-mock-3.1.1/.pre-commit-config.yaml       2020-06-04 
16:32:57.000000000 +0200
@@ -6,7 +6,7 @@
       - id: black
         args: [--safe, --quiet]
   - repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: v2.4.0
+    rev: v2.5.0
     hooks:
       - id: trailing-whitespace
       - id: end-of-file-fixer
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/CHANGELOG.rst 
new/pytest-mock-3.1.1/CHANGELOG.rst
--- old/pytest-mock-3.1.0/CHANGELOG.rst 2020-04-18 17:16:30.000000000 +0200
+++ new/pytest-mock-3.1.1/CHANGELOG.rst 2020-06-04 16:32:57.000000000 +0200
@@ -1,3 +1,11 @@
+3.1.1 (2020-05-31)
+------------------
+
+* Fixed performance regression caused by the ``ValueError`` raised
+  when ``mocker`` is used as context manager (`#191`_).
+
+.. _#191: https://github.com/pytest-dev/pytest-mock/issues/191
+
 3.1.0 (2020-04-18)
 ------------------
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/PKG-INFO 
new/pytest-mock-3.1.1/PKG-INFO
--- old/pytest-mock-3.1.0/PKG-INFO      2020-04-18 17:16:34.000000000 +0200
+++ new/pytest-mock-3.1.1/PKG-INFO      2020-06-04 16:33:01.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: pytest-mock
-Version: 3.1.0
+Version: 3.1.1
 Summary: Thin-wrapper around the mock package for easier use with pytest
 Home-page: https://github.com/pytest-dev/pytest-mock/
 Author: Bruno Oliveira
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/setup.cfg 
new/pytest-mock-3.1.1/setup.cfg
--- old/pytest-mock-3.1.0/setup.cfg     2020-04-18 17:16:34.000000000 +0200
+++ new/pytest-mock-3.1.1/setup.cfg     2020-06-04 16:33:01.000000000 +0200
@@ -1,6 +1,3 @@
-[bdist_wheel]
-universal = 1
-
 [egg_info]
 tag_build = 
 tag_date = 0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/src/pytest_mock/_version.py 
new/pytest-mock-3.1.1/src/pytest_mock/_version.py
--- old/pytest-mock-3.1.0/src/pytest_mock/_version.py   2020-04-18 
17:16:33.000000000 +0200
+++ new/pytest-mock-3.1.1/src/pytest_mock/_version.py   2020-06-04 
16:33:01.000000000 +0200
@@ -1,4 +1,4 @@
 # coding: utf-8
 # file generated by setuptools_scm
 # don't change, don't track in version control
-version = '3.1.0'
+version = '3.1.1'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/src/pytest_mock/plugin.py 
new/pytest-mock-3.1.1/src/pytest_mock/plugin.py
--- old/pytest-mock-3.1.0/src/pytest_mock/plugin.py     2020-04-18 
17:16:30.000000000 +0200
+++ new/pytest-mock-3.1.1/src/pytest_mock/plugin.py     2020-06-04 
16:32:57.000000000 +0200
@@ -158,30 +158,20 @@
             module, registering the patch to stop it later and returns the
             mock object resulting from the mock call.
             """
-            self._enforce_no_with_context(inspect.stack())
             p = mock_func(*args, **kwargs)
             mocked = p.start()
             self._patches.append(p)
             if hasattr(mocked, "reset_mock"):
                 self._mocks.append(mocked)
+                # check if `mocked` is actually a mock object, as depending on 
autospec or target
+                # parameters `mocked` can be anything
+                if hasattr(mocked, "__enter__"):
+                    mocked.__enter__.side_effect = ValueError(
+                        "Using mocker in a with context is not supported. "
+                        
"https://github.com/pytest-dev/pytest-mock#note-about-usage-as-context-manager";
+                    )
             return mocked
 
-        def _enforce_no_with_context(self, stack):
-            """raises a ValueError if mocker is used in a with context"""
-            caller = stack[2]
-            frame = caller[0]
-            info = inspect.getframeinfo(frame)
-            if info.code_context is None:
-                # no source code available (#169)
-                return
-            code_context = " ".join(info.code_context).strip()
-
-            if code_context.startswith("with mocker."):
-                raise ValueError(
-                    "Using mocker in a with context is not supported. "
-                    
"https://github.com/pytest-dev/pytest-mock#note-about-usage-as-context-manager";
-                )
-
         def object(self, *args, **kwargs):
             """API to mock.patch.object"""
             return self._start_patch(self.mock_module.patch.object, *args, 
**kwargs)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/src/pytest_mock.egg-info/PKG-INFO 
new/pytest-mock-3.1.1/src/pytest_mock.egg-info/PKG-INFO
--- old/pytest-mock-3.1.0/src/pytest_mock.egg-info/PKG-INFO     2020-04-18 
17:16:33.000000000 +0200
+++ new/pytest-mock-3.1.1/src/pytest_mock.egg-info/PKG-INFO     2020-06-04 
16:33:01.000000000 +0200
@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: pytest-mock
-Version: 3.1.0
+Version: 3.1.1
 Summary: Thin-wrapper around the mock package for easier use with pytest
 Home-page: https://github.com/pytest-dev/pytest-mock/
 Author: Bruno Oliveira
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pytest-mock-3.1.0/tests/test_pytest_mock.py 
new/pytest-mock-3.1.1/tests/test_pytest_mock.py
--- old/pytest-mock-3.1.0/tests/test_pytest_mock.py     2020-04-18 
17:16:30.000000000 +0200
+++ new/pytest-mock-3.1.1/tests/test_pytest_mock.py     2020-06-04 
16:32:57.000000000 +0200
@@ -773,7 +773,7 @@
 
 def test_abort_patch_context_manager(mocker):
     with pytest.raises(ValueError) as excinfo:
-        with mocker.patch("some_package"):
+        with mocker.patch("json.loads"):
             pass
 
     expected_error_msg = (
@@ -784,6 +784,26 @@
     assert str(excinfo.value) == expected_error_msg
 
 
+def test_context_manager_patch_example(mocker):
+    """Our message about misusing mocker as a context manager should not 
affect mocking
+    context managers (see #192)"""
+
+    class dummy_module:
+        class MyContext:
+            def __enter__(self, *args, **kwargs):
+                return 10
+
+            def __exit__(self, *args, **kwargs):
+                pass
+
+    def my_func():
+        with dummy_module.MyContext() as v:
+            return v
+
+    m = mocker.patch.object(dummy_module, "MyContext")
+    assert isinstance(my_func(), mocker.MagicMock)
+
+
 def test_abort_patch_context_manager_with_stale_pyc(testdir):
     """Ensure we don't trigger an error in case the frame where mocker.patch 
is being
     used doesn't have a 'context' (#169)"""


Reply via email to