Skip to content

Comments

bpo-35978: Correctly skips venv tests in venvs#12220

Merged
zooba merged 2 commits intopython:masterfrom
zooba:bpo-35978
Mar 21, 2019
Merged

bpo-35978: Correctly skips venv tests in venvs#12220
zooba merged 2 commits intopython:masterfrom
zooba:bpo-35978

Conversation

@zooba
Copy link
Member

@zooba zooba commented Mar 7, 2019

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

@vstinner
Copy link
Member

vstinner commented Mar 8, 2019

I prefer the current skip message:

test_with_pip (test.test_venv.EnsurePipTest) ... skipped 'Test not appropriate in a venv'

The new one is more surprising:

test_with_pip (test.test_venv.EnsurePipTest) ... skipped 'Test requires venv.create'

I don't get it: venv.create() doesn't exist? Example with test_posix:

test_pwritev_flags (test.test_posix.PosixTester) ... skipped 'test needs os.RWF_SYNC'

Usually "need xxx" means that a function is not available on a platform.

@vstinner
Copy link
Member

vstinner commented Mar 8, 2019

I confirm that this PR fix https://bugs.python.org/issue35978 on Linux.

vstinner@apu$ ./python -m venv venv

vstinner@apu$ ./python -m test test_venv -v
== CPython 3.8.0a2+ (heads/master:dc078947a5, Mar 7 2019, 13:03:13) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]
== Linux-4.20.13-200.fc29.x86_64-x86_64-with-glibc2.28 little-endian
== cwd: /home/vstinner/prog/python/master/build/test_python_29002
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
Run tests sequentially
0:00:00 load avg: 0.57 [1/1] test_venv
test_defaults (test.test_venv.BasicTest) ... ok
test_executable (test.test_venv.BasicTest) ... ok
test_executable_symlinks (test.test_venv.BasicTest) ... ok
test_isolation (test.test_venv.BasicTest) ... ok
test_multiprocessing (test.test_venv.BasicTest) ... ok
test_overwrite_existing (test.test_venv.BasicTest) ... ok
test_prefixes (test.test_venv.BasicTest) ... ok
test_prompt (test.test_venv.BasicTest) ... ok
test_symlinking (test.test_venv.BasicTest) ... ok
test_unicode_in_batch_file (test.test_venv.BasicTest) ... skipped 'only relevant on Windows'
test_unoverwritable_fails (test.test_venv.BasicTest) ... ok
test_upgrade (test.test_venv.BasicTest) ... ok
test_devnull (test.test_venv.EnsurePipTest) ... ok
test_explicit_no_pip (test.test_venv.EnsurePipTest) ... ok
test_no_pip_by_default (test.test_venv.EnsurePipTest) ... ok
test_with_pip (test.test_venv.EnsurePipTest) ... ok

----------------------------------------------------------------------

Ran 16 tests in 19.850s

OK (skipped=1)

== Tests result: SUCCESS ==

1 test OK.

Total duration: 19 sec 968 ms
Tests result: SUCCESS
vstinner@apu$ ./venv/bin/python -m test test_venv -v
== CPython 3.8.0a2+ (heads/master:dc078947a5, Mar 7 2019, 13:03:13) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]
== Linux-4.20.13-200.fc29.x86_64-x86_64-with-glibc2.28 little-endian
== cwd: /home/vstinner/prog/python/master/build/test_python_29042
== CPU count: 8
== encodings: locale=UTF-8, FS=utf-8
Run tests sequentially
0:00:00 load avg: 0.64 [1/1] test_venv
test_defaults (test.test_venv.BasicTest) ... ok
test_executable (test.test_venv.BasicTest) ... skipped 'Test requires venv.create'
test_executable_symlinks (test.test_venv.BasicTest) ... ok
test_isolation (test.test_venv.BasicTest) ... ok
test_multiprocessing (test.test_venv.BasicTest) ... skipped 'Test requires venv.create'
test_overwrite_existing (test.test_venv.BasicTest) ... ok
test_prefixes (test.test_venv.BasicTest) ... skipped 'Test requires venv.create'
test_prompt (test.test_venv.BasicTest) ... ok
test_symlinking (test.test_venv.BasicTest) ... ok
test_unicode_in_batch_file (test.test_venv.BasicTest) ... skipped 'only relevant on Windows'
test_unoverwritable_fails (test.test_venv.BasicTest) ... ok
test_upgrade (test.test_venv.BasicTest) ... ok
test_devnull (test.test_venv.EnsurePipTest) ... skipped 'Test requires venv.create'
test_explicit_no_pip (test.test_venv.EnsurePipTest) ... skipped 'Test requires venv.create'
test_no_pip_by_default (test.test_venv.EnsurePipTest) ... skipped 'Test requires venv.create'
test_with_pip (test.test_venv.EnsurePipTest) ... skipped 'Test requires venv.create'

----------------------------------------------------------------------

Ran 16 tests in 0.119s

OK (skipped=8)

== Tests result: SUCCESS ==

1 test OK.

Total duration: 236 ms
Tests result: SUCCESS

requireVenvCreate = unittest.skipUnless(
sys.platform.startswith('win')
or sys.prefix == sys.base_prefix,
'Test requires venv.create')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

skipInVenv = unittest.skipIf(sys.prefix != sys.base_prefix,
'Test not appropriate in a venv')
requireVenvCreate = unittest.skipUnless(
sys.platform.startswith('win')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zooba
Copy link
Member Author

zooba commented Mar 9, 2019

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.

@vstinner
Copy link
Member

Sorry, I don't have the bandwidth to review this PR :-(

@zooba
Copy link
Member Author

zooba commented Mar 21, 2019

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :-)

@zooba zooba merged commit 8bba81f into python:master Mar 21, 2019
@miss-islington
Copy link
Contributor

Thanks @zooba for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-12485 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 21, 2019
Also fixes venvs from the build directory on Windows.
(cherry picked from commit 8bba81f)

Co-authored-by: Steve Dower <[email protected]>
miss-islington added a commit that referenced this pull request Mar 21, 2019
Also fixes venvs from the build directory on Windows.
(cherry picked from commit 8bba81f)

Co-authored-by: Steve Dower <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants