When building the latest python-daemon on rawhide we run into these error:
/usr/bin/python2 -m unittest discover BUILDSTDERR: .........................................................................................................EEEEE...........................................................................................................................................................................s....................s..................................................... BUILDSTDERR: ====================================================================== BUILDSTDERR: ERROR: test_returns_expected_result (test_version.get_changelog_path_TestCase) BUILDSTDERR: test_version.get_changelog_path_TestCase.test_returns_expected_result (simple) BUILDSTDERR: ---------------------------------------------------------------------- BUILDSTDERR: _StringException: Traceback (most recent call last): BUILDSTDERR: File "test_version.py", line 1149, in test_returns_expected_result BUILDSTDERR: result = version.get_changelog_path(**args) BUILDSTDERR: File "version.py", line 564, in get_changelog_path BUILDSTDERR: build_py_command = distutils.command.build_py.build_py(distribution) BUILDSTDERR: File "/usr/lib/python2.7/site-packages/setuptools/__init__.py", line 163, in __init__ BUILDSTDERR: _Command.__init__(self, dist) BUILDSTDERR: File "/usr/lib64/python2.7/distutils/cmd.py", line 59, in __init__ BUILDSTDERR: raise TypeError, "dist must be a Distribution instance" BUILDSTDERR: TypeError: dist must be a Distribution instance ....
Full logs at: https://koji.fedoraproject.org/koji/taskinfo?taskID=37177129
Reported in bugzilla at: https://bugzilla.redhat.com/show_bug.cgi?id=1734773
I'm trying to look at it but any clues would be appreciated :)
The problem here is caused by mocking because mocked Distribution instance passes the isinstance test in distutils in Python 3 but it doesn't in Python 2.
isinstance
https://pagure.io/python-daemon/blob/master/f/test_version.py#_1124
# Python 2 ipdb> self.test_distribution <MagicMock spec='instance' id='140499578745232'> ipdb> from distutils.dist import Distribution ipdb> isinstance(self.test_distribution, Distribution) False # Python 3 ipdb> self.test_distribution <MagicMock spec='Distribution' id='140060652871248'> ipdb> from distutils.dist import Distribution ipdb> isinstance(self.test_distribution, Distribution) True
Python 2 for some reason does not replace the __class__ attribute of mocked Distribution object which can be done manually and it works. I don't know if there is a better solution.
__class__
self.test_distribution.__class__ = distutils.dist.Distribution
It is not pretty and it's done automatically in Python 3 but it works for all Pythons and it changes just the MagicMock instance.
It should work with Python 2 as well. I don't know why it does not.
https://cpython-test-docs.readthedocs.io/en/latest/library/unittest.mock.html#unittest.mock.Mock
I've just tried it on my F30 machine, tests are passing for both py2 and py3
Fun, I just reproduced this in a rawhide container (fails indeed only for py2 there).
And confirmed that:
+ self.test_distribution.__class__ = distutils.dist.Distribution
fixes it
I ended up with patching the Fedora package with this one-liner. I'm leaving this ticket open, up to you if you want to integrate this patch upstream or leave it downstream in the package.
It would be also nice to include Python 2.7 in the tox configuration to catch problems like this one earlier. I mean, if it works with Python 2 why not to test it with it.
Because this code base is explicitly dropping support for Python 2 (see https://pagure.io/python-daemon/issue/44 ), I am closing this issue.
Thanks for the report.
Metadata Update from @bignose: - Issue close_status updated to: Invalid - Issue status updated to: Closed (was: Open)