Skip to content

Commit bfcee8e

Browse files
committed
Fix python.healthy() check with stdlib module clashes
1 parent 1509dc4 commit bfcee8e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pre_commit/languages/python.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def healthy(prefix, language_version):
147147
retcode, _, _ = cmd_output_b(
148148
'python', '-c',
149149
'import ctypes, datetime, io, os, ssl, weakref',
150+
cwd='/',
150151
retcode=None,
151152
)
152153
return retcode == 0

tests/languages/python_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import mock
88
import pytest
99

10+
import pre_commit.constants as C
1011
from pre_commit.languages import python
12+
from pre_commit.prefix import Prefix
1113

1214

1315
def test_norm_version_expanduser():
@@ -48,3 +50,11 @@ def test_find_by_sys_executable(exe, realpath, expected):
4850
with mock.patch.object(os.path, 'realpath', return_value=realpath):
4951
with mock.patch.object(python, 'find_executable', lambda x: x):
5052
assert python._find_by_sys_executable() == expected
53+
54+
55+
def test_healthy_types_py_in_cwd(tmpdir):
56+
with tmpdir.as_cwd():
57+
# even if a `types.py` file exists, should still be healthy
58+
tmpdir.join('types.py').ensure()
59+
# this env doesn't actually exist (for test speed purposes)
60+
assert python.healthy(Prefix(str(tmpdir)), C.DEFAULT) is True

0 commit comments

Comments
 (0)