https://bugzilla.redhat.com/show_bug.cgi?id=2081968
Bug ID: 2081968 Summary: python-rpmautospec fails to build with Python 3.11: unittest.mock.InvalidSpecError: Cannot spec a Mock object. Product: Fedora Version: rawhide Status: NEW Component: python-rpmautospec Assignee: asaleh@redhat.com Reporter: thrnciar@redhat.com QA Contact: extras-qa@fedoraproject.org CC: asaleh@redhat.com, epel-packagers-sig@lists.fedoraproject.org, infra-sig@lists.fedoraproject.org, mhroncok@redhat.com, michel@michel-slm.name, nphilipp@redhat.com, thrnciar@redhat.com Blocks: 2016048 (PYTHON3.11) Target Milestone: --- Classification: Fedora
python-rpmautospec fails to build with Python 3.11.0a7.
=================================== FAILURES =================================== _____________________________ test_main_valid_args _____________________________ [gw0] linux -- Python 3.11.0 /usr/bin/python3
pkg_converter_mock = <MagicMock name='PkgConverter' id='139757742069840'> specfile = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_main_valid_args0/test/test.spec')
@unittest.mock.patch("rpmautospec.subcommands.convert.PkgConverter") def test_main_valid_args(pkg_converter_mock, specfile):
pkg_converter = unittest.mock.Mock(spec=convert.PkgConverter)()
tests/rpmautospec/subcommands/test_convert.py:75: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /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 0x7f1be36ae950> spec = <MagicMock name='PkgConverter' id='139757742069840'>, 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=<MagicMock name='PkgConverter' id='139757742069840'>]
/usr/lib64/python3.11/unittest/mock.py:493: InvalidSpecError =========================== short test summary info ============================ FAILED tests/rpmautospec/subcommands/test_convert.py::test_main_valid_args - ... ======================== 1 failed, 359 passed in 32.56s ========================
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-ra...
For all our attempts to build python-rpmautospec with Python 3.11, see: https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/python-r...
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.
Referenced Bugs:
https://bugzilla.redhat.com/show_bug.cgi?id=2016048 [Bug 2016048] Python 3.11
https://bugzilla.redhat.com/show_bug.cgi?id=2081968
Tomáš Hrnčiar thrnciar@redhat.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Depends On| |2081969
Referenced Bugs:
https://bugzilla.redhat.com/show_bug.cgi?id=2081969 [Bug 2081969] python-rpmautospec: FTBFS in Fedora Rawhide
https://bugzilla.redhat.com/show_bug.cgi?id=2081968 Bug 2081968 depends on bug 2081969, which changed state.
Bug 2081969 Summary: python-rpmautospec: FTBFS in Fedora Rawhide https://bugzilla.redhat.com/show_bug.cgi?id=2081969
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |CLOSED Resolution|--- |NOTABUG
https://bugzilla.redhat.com/show_bug.cgi?id=2081968
--- Comment #1 from Miro Hrončok mhroncok@redhat.com --- Replacing:
pkg_converter = unittest.mock.Mock(spec=convert.PkgConverter)()
...with:
pkg_converter = convert.PkgConverter()
...does the trick. convert.PkgConverter is already a mock.
https://bugzilla.redhat.com/show_bug.cgi?id=2081968
Nils Philippsen nphilipp@redhat.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Assignee|asaleh@redhat.com |nphilipp@redhat.com Status|NEW |ASSIGNED
--- Comment #2 from Nils Philippsen nphilipp@redhat.com --- (In reply to Miro Hrončok from comment #1)
Replacing:
pkg_converter = unittest.mock.Mock(spec=convert.PkgConverter)()
...with:
pkg_converter = convert.PkgConverter()
...does the trick. convert.PkgConverter is already a mock.
Yeah, but that just seems to hide issues. I didn't write the test myself and I'm still figuring out how it's supposed to work but it looks pretty much as if things should be run through the real `PkgConverter` object and the mock just exists to be able to inspect what was called and such.
https://bugzilla.redhat.com/show_bug.cgi?id=2081968
--- Comment #3 from Nils Philippsen nphilipp@redhat.com --- Hmm, I guess I was wrong with my assumption, but there's still a way to make this nicer.
https://bugzilla.redhat.com/show_bug.cgi?id=2081968
Nils Philippsen nphilipp@redhat.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |CLOSED Fixed In Version| |python-rpmautospec-0.2.8-1. | |fc37 Resolution|--- |RAWHIDE Last Closed| |2022-05-16 16:31:48
epel-packagers-sig@lists.fedoraproject.org