GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 3.12.0a7 changes behavior of PropertyMock · Issue #103329 · python/cpython

3.12.0a7 changes behavior of PropertyMock #103329

New issue
Copy link
New issue
Copy link
Closed
#103358
Closed
3.12.0a7 changes behavior of PropertyMock#103329
#103358
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@freakboy3742
freakboy3742
opened on Apr 7, 2023
Issue body actions

Bug report

3.12.0a7 changed the behavior of unittest.mock.PropertyMock

Setup:

from unittest.mock import MagicMock, PropertyMock
m = MagicMock()
p1 = PropertyMock(return_value=3)
p2 = PropertyMock(side_effect=ValueError)
type(m).foo = p1
type(m).bar = p2

In Python 3.12.0a6 and earlier, m.foo evaluates as 3, and m.bar raises a ValueError.

In Python 3.12.0a7, m.foo evaluates as 3, and m.bar returns <MagicMock name='mock.bar' id=...>

Your environment

  • CPython versions tested on: 3.12.0a7, 3.12.0a6, 3.11.2, 3.10.10, 3.9.16, 3.8.16
  • Operating system and architecture:
    • macOS Ventura 13.2.1, on an M1 MacBook Pro.
    • GitHub Actions macOS 12 x86_64
    • GitHub Actions Ubuntu 22.04
    • GitHub Actions Windows Server 2022

Linked PRs

  • gh-103329: Add regression test for PropertyMock with side effect #103358
  • [3.11] gh-103329: Add regression test for PropertyMock with side effect (GH-103358) #103364

Activity

  1. freakboy3742
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Apr 7, 2023
  2. arhadthedev
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Apr 7, 2023
  3. sunmy2019 commented on Apr 7, 2023

    @sunmy2019
    sunmy2019
    on Apr 7, 2023
    Member
    More actions

    A known on-going failure was introduced in the related components: aa0a73d

    See #103272

    Can anyone test if it starts here?

  4. freakboy3742 commented on Apr 7, 2023

    @freakboy3742
    freakboy3742
    on Apr 7, 2023
    ContributorAuthor
    More actions

    @sunmy2019 I'm not sure aa0a73d is the cause here (or, at least, it isn't the only thing in play); in my testing, that commit still raises a ValueError - although the presentation is slightly different, as it also includes

    >>> m.bar
    Traceback (most recent call last):
      File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 2957, in __get__
        return self()
               ^^^^^^
      File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 1128, in __call__
        return self._mock_call(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 1132, in _mock_call
        return self._execute_mock_call(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 1187, in _execute_mock_call
        raise effect
    ValueError
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/rkm/projects/python/cpython/github/Lib/unittest/mock.py", line 656, in __getattr__
        if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    SystemError: <method 'startswith' of 'str' objects> returned a result with an exception set
    
    

    whereas 3.11 et al raise:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 2932, in __get__
        return self()
               ^^^^^^
      File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 1118, in __call__
        return self._mock_call(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 1122, in _mock_call
        return self._execute_mock_call(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py", line 1177, in _execute_mock_call
        raise effect
    ValueError
    
  5. sunmy2019 commented on Apr 7, 2023

    @sunmy2019
    sunmy2019
    on Apr 7, 2023
    Member
    More actions

    Looks like it was fixed by #103332

    With current main, I got the same output as in your python3.11. @freakboy3742

  6. carljm commented on Apr 7, 2023

    @carljm
    carljm
    on Apr 7, 2023
    Member
    More actions

    Before closing this issue, we should add a test for this case that would have failed on the original breaking PR.

  7. freakboy3742
    added a commit that references this issue on Apr 8, 2023

    Add regression test for python#103329.

    26f2709
  8. freakboy3742 commented on Apr 8, 2023

    @freakboy3742
    freakboy3742
    on Apr 8, 2023
    ContributorAuthor
    More actions

    Confirming this has been fixed by #103332. I've submitted some regression tests in #103358.

    Reacted by Carl Meyer
  9. carljm
    closed this as completedin #103358on Apr 8, 2023
  10. carljm
    added a commit that references this issue on Apr 8, 2023

    gh-103329: Add regression test for PropertyMock with side effect (#10…

    26c6598
  11. miss-islington
    added 2 commits that reference this issue on Apr 8, 2023

    pythongh-103329: Add regression test for PropertyMock with side effect (

    6c3da92

    gh-103329: Add regression test for PropertyMock with side effect (GH-…

    29a1e89
  12. warsaw
    added a commit that references this issue on Apr 11, 2023

    pythongh-103329: Add regression test for PropertyMock with side effect (

    8c2786a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.