Bug 2082577

Summary: python-pyglet fails to build with Python 3.11: unittest.mock.InvalidSpecError: Cannot spec a Mock object.
Product: [Fedora] Fedora Reporter: Tomáš Hrnčiar <thrnciar>
Component: python-pygletAssignee: Petr Viktorin (pviktori) <pviktori>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: mhroncok, orion, pviktori, python-sig, thrnciar
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-pyglet-1.5.23-2.fc37 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-06-16 23:20:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2016048    

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.