Bug 2082577 - python-pyglet fails to build with Python 3.11: unittest.mock.InvalidSpecError: Cannot spec a Mock object.
Summary: python-pyglet fails to build with Python 3.11: unittest.mock.InvalidSpecError...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: python-pyglet
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Petr Viktorin (pviktori)
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.11
TreeView+ depends on / blocked
 
Reported: 2022-05-06 13:02 UTC by Tomáš Hrnčiar
Modified: 2022-06-16 23:20 UTC (History)
5 users (show)

Fixed In Version: python-pyglet-1.5.23-2.fc37
Clone Of:
Environment:
Last Closed: 2022-06-16 23:20:07 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github pyglet pyglet issues 606 0 None open tests/unit/test_events.py::test_push_handlers_instance with py3.11: Cannot spec a Mock object. 2022-05-20 13:42:05 UTC

Description Tomáš Hrnčiar 2022-05-06 13:02:20 UTC
python-pyglet fails to build with Python 3.11.0a7.


=================================== FAILURES ===================================
_________________________ test_push_handlers_instance __________________________

dispatcher = <pyglet.event.EventDispatcher object at 0x7fecc7738d90>
mock_instance_handler = <Mock id='140654356780816'>

    def test_push_handlers_instance(dispatcher, mock_instance_handler):
        dispatcher.push_handlers(mock_instance_handler)
>       result = dispatcher.dispatch_event('mock_event')

tests/unit/test_events.py:81: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyglet/event.py:404: in dispatch_event
    handler = handler()
/usr/lib64/python3.11/weakref.py:73: in __call__
    return self._meth_type(func, obj)
/usr/lib64/python3.11/unittest/mock.py:1090: in __init__
    _safe_super(CallableMixin, self).__init__(
/usr/lib64/python3.11/unittest/mock.py:442: in __init__
    self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[AttributeError('_mock_methods') raised in repr()] Mock object at 0x7feca5010cd0>
spec = <Mock name='mock.mock_event.__func__' id='140654357321744'>
spec_set = None, _spec_as_instance = False, _eat_self = False

    def _mock_add_spec(self, spec, spec_set, _spec_as_instance=False,
                       _eat_self=False):
        if _is_instance_mock(spec):
>           raise InvalidSpecError(f'Cannot spec a Mock object. [object={spec!r}]')
E           unittest.mock.InvalidSpecError: Cannot spec a Mock object. [object=<Mock name='mock.mock_event.__func__' id='140654357321744'>]

/usr/lib64/python3.11/unittest/mock.py:493: InvalidSpecError

bpo-43478: Mocks can no longer be provided as the specs for other Mocks. As a result, an already-mocked object cannot be passed to mock.Mock(). This can uncover bugs in tests since these Mock-derived Mocks will always pass certain tests (e.g. isinstance) and builtin assert functions (e.g. assert_called_once_with) will unconditionally pass.

https://bugs.python.org/issue?@action=redirect&bpo=43478
https://docs.python.org/3.11/whatsnew/3.11.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/04369678-python-pyglet/

For all our attempts to build python-pyglet with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/python-pyglet/

Testing and mass rebuild of packages is happening in copr. You can follow these instructions to test locally in mock if your package builds with Python 3.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires), so if this package is required a lot, it's important for us to get it fixed soon.
We'd appreciate help from the people who know this package best, but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Miro Hrončok 2022-06-16 23:20:07 UTC
Since this is a test issue (with mocking) I've skipped the test for now. Can be eventually fixed upstream.


Note You need to log in before you can comment on or make changes to this bug.