test_bdb and test_distutils fail on installed Python 3.9, 3.10 and 3.11 (setuptools 60.9.3, pip 22.0.4) #91169
Copy link
Copy link
Closed
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetestsTests in the Lib/test dirTests in the Lib/test dir
Description
| BPO | 47013 |
|---|---|
| Nosy | @jaraco, @vstinner, @ned-deily |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2022-03-14.16:14:07.532>
labels = ['3.8', '3.9', '3.10', '3.11', '3.7', 'tests']
title = 'test_bdb and test_distutils fail on installed Python 3.9, 3.10 and 3.11 (setuptools 60.9.3, pip 22.0.4)'
updated_at = <Date 2022-03-16.01:15:39.379>
user = 'https://github.com/vstinner'bugs.python.org fields:
activity = <Date 2022-03-16.01:15:39.379>
actor = 'jaraco'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Tests']
creation = <Date 2022-03-14.16:14:07.532>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 47013
keywords = []
message_count = 8.0
messages = ['415157', '415158', '415160', '415161', '415162', '415164', '415180', '415311']
nosy_count = 3.0
nosy_names = ['jaraco', 'vstinner', 'ned.deily']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue47013'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifetestsTests in the Lib/test dirTests in the Lib/test dir
Activity
vstinner commentedon Mar 14, 2022
Since build 298, test_bdb test_distutils fail on s390x Fedora Rawhide Clang Installed 3.10:
https://buildbot.python.org/all/#/builders/694/builds/298
2 changes of build 298:
Logs:
======================================================================
FAIL: test_skip (test.test_bdb.StateTestCase)
----------------------------------------------------------------------
vstinner commentedon Mar 14, 2022
Reproduce:
setuptools installs this file:
vstinner commentedon Mar 14, 2022
See: [BUG] Having setuptools installed causes cpython stdlib build to fail
pypa/setuptools#3007
vstinner commentedon Mar 14, 2022
x86 Gentoo Installed with X 3.9:
https://buildbot.python.org/all/#builders/527/builds/474
4 tests failed:
test_bdb test_distutils test_importlib test_peg_generator
Python 3.9 gets two more issues: test_importlib and test_peg_generator.
======================================================================
FAIL: test_package_discovery (test.test_importlib.test_main.DiscoveryTests)
----------------------------------------------------------------------
[-]3.10: test_bdb test_distutils fail on s390x Fedora Rawhide Clang Installed 3.10[/-][+]test_bdb and test_distutils fail on installed Python 3.9 and 3.10 (setuptools 60.9.3, pip 22.0.4)[/+][-]3.10: test_bdb test_distutils fail on s390x Fedora Rawhide Clang Installed 3.10[/-][+]test_bdb and test_distutils fail on installed Python 3.9 and 3.10 (setuptools 60.9.3, pip 22.0.4)[/+]vstinner commentedon Mar 14, 2022
AMD64 Fedora Stable Clang Installed 3.x:
https://buildbot.python.org/all/#builders/350/builds/1621
2 re-run tests:
test_bdb test_distutils
[-]test_bdb and test_distutils fail on installed Python 3.9 and 3.10 (setuptools 60.9.3, pip 22.0.4)[/-][+]test_bdb and test_distutils fail on installed Python 3.9, 3.10 and 3.11 (setuptools 60.9.3, pip 22.0.4)[/+]10 remaining items
jaraco commentedon Jun 17, 2022
From pypa/setuptools#3007:
If tiran is right, then Setuptools is already doing everything it can not to interfere with CPython builds.
It appears that Setuptools is unable to do anything to detect that the stdlib distutils is to be preferred.
Trying to think outside the box, maybe there's a way that the distutils hook could be extended to detect the import of any module matching
test.test_, and if that's the case, disable the hook as well.It's not simply enough to detect an attempt to import
test, becausetest.supportis available and used by third party packages.In fact, maybe Setuptools could simply disable the hook if the specifically-implicated modules are encountered.
I can try that, maybe using the repro above.
jaraco commentedon Jun 17, 2022
I was able to repro at least some of the failures with this dockerfile:
Here's an excerpt from the output:
jaraco commentedon Jun 17, 2022
Attempting to install a pre-release of setuptools, I find that the custom build of Python is inadequate because
_ctypesisn't available, soimport wheel.macosx_libfilefails. I need to figure out what dependencies are needed to get ctypes to build.I suspect
libffi-devwas the required dependency, but I've just copied all of the dependencies from the developer guide:jaraco commentedon Jun 17, 2022
My attempts to have setuptools selectively disable the distutils override worked for all of the tests except
test_bdb. The failing test is test_skip. I suspected and then confirmed that that test fails even if the distutils patching is disabled but the Finder is still present. It seems the presence of another finder on meta_path is sufficient to breaktest_bdb.StateTestCase.test_skip.jaraco commentedon Jun 17, 2022
Here's a repro not involving Setuptools showing how
test_bdbis sensitive tosys.meta_pathmanipulation:It fails with a similar error:
jaraco commentedon Jun 17, 2022
Based on this finding, I don't think there's anything that Setuptools can do short of completely removing the hook, which is a non-starter because (a) it would break all users relying on the hook to provide distutils when it's not available in the stdlib and (b) it would remove the ability for use cases still reliant on stdlib to opt out.
I suggest we'll want to find a fix for test_bdb independent of the concerns introduced by setuptools.
jaraco commentedon Jun 17, 2022
With this Dockerfile, I can confirm the proposed fix in Setuptools has the desired effect:
Unfortunately, it also creates its own regression in
test_venv:And annoyingly, that error message is all but worthless for diagnosis.
jaraco commentedon Jun 17, 2022
After adding a breakpoint where the error is occurring (pytest would do this automatically with
--pdb), I'm able to inspect the error:It seems there's a new issue, probably brought on by changes in Setuptools.
jaraco commentedon Jun 17, 2022
The failure looks suspiciously similar to pypa/setuptools#2940.
jaraco commentedon Jun 17, 2022
Okay, so Setuptools fixed that issue and released it in 60.0.3, but the version of Setuptools installed into the virtualenv doesn't have that fix. But that doesn't explain why the issue only emerges when the version of Setuptools is bumped.
Aah. I get it. This test is running a venv with
--system-site-packages, so thedistutils-precedence.pthfor the system site packages is taking effect, enablingSETUPTOOLS_USE_DISTUTILS=local, but then because the venv gets an old version of Setuptools with the bug in it, that version gets invoked. This bug will go away when the version of Setuptools installed into the venvs is updated.jaraco commentedon Jun 17, 2022
At this point, pypa/setuptools#3386 (to be released with Setuptools>=62.5.0) and gh-93962 should fix the issue.
yilun11 commentedon Aug 13, 2022
@jaraco I upgraded to setuptools 64.0.3 and still get these errors. Is there a solution?
Using docker pull registry.gitlab.com/python-devs/ci-images:active from README for dev container
python3 -m test test_importlib test_distutils test_peg_generator
All 3 tests fail due to no module found. Pip install --upgrade setuptools doesn't resolve although version is 64.0.3. I also tried make from source and it throws the error at test_peg_generator.
Thanks!
jaraco commentedon Aug 14, 2022
@yilun11 I suspect your issue is different than this one. I can indeed produce an error if I use your repro:
However, I also observe that I get the same error for any test module:
When I look at the Python lib directory, I see a
supportsubpackage, but no modules for the tests themselves. I suspect the image you're using simply doesn't have the Python tests installed, so you shouldn't expect it to work. TheModuleNotFoundErroris a fairly generic error not specific to this issue. This issue is specific to a few select modules not working when Setuptools is present. You can tell if you're affected by the issue if you can work around it by settingSETUPTOOLS_USE_DISTUTILS=stdlib.To close the loop on this issue, I've confirmed that the repro that previously failed no longer fails with the latest Setuptools: