bpo-35978: Correctly skips venv tests in venvs#12220
Conversation
|
I prefer the current skip message: The new one is more surprising: I don't get it: venv.create() doesn't exist? Example with test_posix: Usually "need xxx" means that a function is not available on a platform. |
|
I confirm that this PR fix https://bugs.python.org/issue35978 on Linux. |
Lib/test/test_venv.py
Outdated
| requireVenvCreate = unittest.skipUnless( | ||
| sys.platform.startswith('win') | ||
| or sys.prefix == sys.base_prefix, | ||
| 'Test requires venv.create') |
There was a problem hiding this comment.
I don't understand why you changed the decorator name and the skip message. I don't understand the new skip message (see my other comment on the PR). Why not just add sys.platform.startswith('win') in skipInVenv?
Lib/test/test_venv.py
Outdated
| skipInVenv = unittest.skipIf(sys.prefix != sys.base_prefix, | ||
| 'Test not appropriate in a venv') | ||
| requireVenvCreate = unittest.skipUnless( | ||
| sys.platform.startswith('win') |
There was a problem hiding this comment.
Can you please add a comment explaining why tests don't need to be skipped on Windows? Is it a new feature of Python 3.8? Is it the new "wrapper" that you merged recently? Maybe add a link to the bpo which added this wrapper.
|
It changed because I added a new decorator to represent "this test requires venv.create to succeed" as distinct from "this test will never work in a venv". I believe mac can also create new venvs from within a venv, at least for Ned's builds, though I haven't tested. There may be tests that never work in a venv regardless of platform. As it turns out, the only reason tests fail in a venv is because they try and create a new one, so the original decorator was unused. Maybe we should have a bug to fix venv.create on Linux? Then we won't need any decorator at all. |
|
Sorry, I don't have the bandwidth to review this PR :-( |
|
I improved the skip message, the check, and added a comment by the decorator. Assuming CI passes, I'll merge. |
| requireVenvCreate = unittest.skipUnless( | ||
| hasattr(sys, '_base_executable') | ||
| or sys.prefix == sys.base_prefix, | ||
| 'cannot run venv.create from within a venv on this platform') |
There was a problem hiding this comment.
I don't recall what was the previous message, but this one explains well why the test is skipped. Better than the current message. Thanks.
vstinner
left a comment
There was a problem hiding this comment.
The test_venv.py LGTM.
I don't understand the venv change, but it seems specific to Windows so I trust Steve to know what he does :-)
|
Thanks @zooba for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
|
GH-12485 is a backport of this pull request to the 3.7 branch. |
Also fixes venvs from the build directory on Windows. (cherry picked from commit 8bba81f) Co-authored-by: Steve Dower <[email protected]>
Also fixes venvs from the build directory on Windows. (cherry picked from commit 8bba81f) Co-authored-by: Steve Dower <[email protected]>
As well as changing the skip decorator, I also slightly reordered the handling of running venv out of a build directory on Windows to minimize the work in the normal (non-build dir) case, and to also handle the venv-from-venv-from-build-directory case (where sysconfig doesn't correctly detect it).
https://bugs.python.org/issue35978