From bfcee8ec9fb5ab8390a225ba6fa64607d50eacb9 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 22 Oct 2019 13:23:57 -0700 Subject: [PATCH] Fix python.healthy() check with stdlib module clashes --- pre_commit/languages/python.py | 1 + tests/languages/python_test.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py index c9bedb68..6eecc0c8 100644 --- a/pre_commit/languages/python.py +++ b/pre_commit/languages/python.py @@ -147,6 +147,7 @@ def py_interface(_dir, _make_venv): retcode, _, _ = cmd_output_b( 'python', '-c', 'import ctypes, datetime, io, os, ssl, weakref', + cwd='/', retcode=None, ) return retcode == 0 diff --git a/tests/languages/python_test.py b/tests/languages/python_test.py index d9d8ecd5..7daff1d4 100644 --- a/tests/languages/python_test.py +++ b/tests/languages/python_test.py @@ -7,7 +7,9 @@ import sys import mock import pytest +import pre_commit.constants as C from pre_commit.languages import python +from pre_commit.prefix import Prefix def test_norm_version_expanduser(): @@ -48,3 +50,11 @@ def test_find_by_sys_executable(exe, realpath, expected): with mock.patch.object(os.path, 'realpath', return_value=realpath): with mock.patch.object(python, 'find_executable', lambda x: x): assert python._find_by_sys_executable() == expected + + +def test_healthy_types_py_in_cwd(tmpdir): + with tmpdir.as_cwd(): + # even if a `types.py` file exists, should still be healthy + tmpdir.join('types.py').ensure() + # this env doesn't actually exist (for test speed purposes) + assert python.healthy(Prefix(str(tmpdir)), C.DEFAULT) is True