Stabilize python default version lookup

For example, for sys.executable:
    /usr/bin/python3 -> python3.7
...the default lookup may return either python3 or python3.7. Make the
order deterministic by iterating over tuple, not set, of candidates.
This commit is contained in:
Ville Skyttä
2019-08-15 08:36:06 +03:00
parent 7c69730ad2
commit fa2e154b41
2 changed files with 24 additions and 3 deletions

View File

@@ -32,3 +32,18 @@ def test_sys_executable_matches(v):
def test_sys_executable_matches_does_not_match(v):
with mock.patch.object(sys, 'version_info', (3, 6, 7)):
assert not python._sys_executable_matches(v)
@pytest.mark.parametrize(
'exe,realpath,expected', (
('/usr/bin/python3', '/usr/bin/python3.7', 'python3'),
('/usr/bin/python', '/usr/bin/python3.7', 'python3.7'),
('/usr/bin/python', '/usr/bin/python', None),
('/usr/bin/python3.6m', '/usr/bin/python3.6m', 'python3.6m'),
('v/bin/python', 'v/bin/pypy', 'pypy'),
),
)
def test_find_by_sys_executable(exe, realpath, expected):
with mock.patch.object(sys, 'executable', exe):
with mock.patch('os.path.realpath', return_value=realpath):
assert python._find_by_sys_executable() == expected