Disable bytecode writing due to pytest's assertion rewrite (DISCUSSION)#810
Disable bytecode writing due to pytest's assertion rewrite (DISCUSSION)#810nicoddemus wants to merge 1 commit into
Conversation
setuptools test suite uses a sandboxed environment in some tests that install wrappers around some builtin functions that access disk (for example os.mkdir). pytest's assertion rewriting mechanism tries to cache the rewritten bytecode by calling "os.mkdir" during the import process, and that breaks the entire suite. As a quick around, disable bytecode writing when running the tests. Related to pytest-dev/pytest#1888
de69aec to
40b1ac3
Compare
|
Thanks very much for the extensive troubleshooting and detailed description. I think the solution here will be to avoid the sandboxing altogether by relying on |
Is sandboxing done by
What should we do with this PR? IMHO I think it is an acceptable workaround for now, it causes a very minimal (I suspect negligible) performance loss when collecting the test suite and only on local runs, as the CI servers use clean VMs for all executions. |
|
After switching the codebase to use tox for test preparation, the tests now pass. Thanks so much for the help on this. |
|
Glad I could help! |
After some investigation I found what the problem related in pytest-dev/pytest#1888 is:
os.mkdir.setuptoolsexecutes some tests in a sandboxed environment which disallows certain functions that modify the disk from being called, such asos.mkdir.os.mkdir, but to raise an error it tries to importSandboxViolation, which again triggers the import hook, which again tries to callos.mkdir, and so on.Here's the relevant part of the traceback from a setuptools job from my fork which uses pytest 3.0.3:
This explains why pytest-dev/pytest#1891 fixed this issue in pytest-3.0: pytest was trying to rewrite a bunch of modules that shouldn't be rewritten in the first place because they were not pytest plugins.
This also explains why this broke again in
3.0.3: pytest-dev/pytest#1934 was introduced. Now pytest will rewrite plugins installed in development mode, so it again tries to rewrite the setuptools own plugin during the sandboxed tests, triggering the sandbox violation.As a quick workaround, I disabled bytecode writing so pytest will re-generate the bytecode but won't cache it into disk.
Another possible solution would be to use
--assert=plainwhich disables the rewrite-hook completely, but then rich assertion errors would be lost.I'm opening this PR in order to discuss other possible solutions to this problem.