Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Avoid calling reset_mock() on a mock of super() to avoid RecursionError #2528

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Nov 18, 2024

Starting with Python 3.12.7 or 3.13.0rc3, the reset_mock() method calls super().

python/cpython#123934

This lead to:

__________________________ test_python_remove_plotter __________________________
    def test_python_remove_plotter():
        """
        Ensure the button states are returned to normal before calling super
        method.
        """
        editor = mock.MagicMock()
        view = mock.MagicMock()
        with mock.patch("builtins.super") as mock_super:
            pm = PythonMode(editor, view)
            pm.set_buttons = mock.MagicMock()
>           mock_super.reset_mock()
tests/modes/test_python3.py:489:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.13/unittest/mock.py:2232: in reset_mock
    super().reset_mock(*args, return_value=return_value, **kwargs)
/usr/lib64/python3.13/unittest/mock.py:2232: in reset_mock
    super().reset_mock(*args, return_value=return_value, **kwargs)
/usr/lib64/python3.13/unittest/mock.py:2232: in reset_mock
    super().reset_mock(*args, return_value=return_value, **kwargs)
E   RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)

We avoid the problem by not needlessly calling reset_mock() in this test at all.

…sionError

Starting with Python 3.12.7 or 3.13.0rc3, the reset_mock() method calls super().

python/cpython#123934

This lead to:

    __________________________ test_python_remove_plotter __________________________
        def test_python_remove_plotter():
            """
            Ensure the button states are returned to normal before calling super
            method.
            """
            editor = mock.MagicMock()
            view = mock.MagicMock()
            with mock.patch("builtins.super") as mock_super:
                pm = PythonMode(editor, view)
                pm.set_buttons = mock.MagicMock()
    >           mock_super.reset_mock()
    tests/modes/test_python3.py:489:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    /usr/lib64/python3.13/unittest/mock.py:2232: in reset_mock
        super().reset_mock(*args, return_value=return_value, **kwargs)
    /usr/lib64/python3.13/unittest/mock.py:2232: in reset_mock
        super().reset_mock(*args, return_value=return_value, **kwargs)
    /usr/lib64/python3.13/unittest/mock.py:2232: in reset_mock
        super().reset_mock(*args, return_value=return_value, **kwargs)
    E   RecursionError: maximum recursion depth exceeded
    !!! Recursion detected (same locals & position)

We avoid the problem by not needlessly calling reset_mock() in this test at all.
Copy link
Member

@carlosperate carlosperate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hroncok! LGTM 👍

@carlosperate carlosperate merged commit de6113a into mu-editor:master Dec 13, 2024
22 of 31 checks passed
@carlosperate carlosperate added this to the 1.2.2 milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants