From f519a62848b0b3e8dca72709a5fc37558eb8e2a7 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 6 Oct 2020 15:31:17 +0800 Subject: [PATCH] tests: support python releases before 3.7 the "capture_output" parameter of subprocess.run() was introduced in python3.7. and subprocess.run() does not exist in python2. so should not rely on them unless we drop the support of python2 and python3.6 Signed-off-by: Kefu Chai --- tests/nodeenv_test.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/nodeenv_test.py b/tests/nodeenv_test.py index ecf182c..9526575 100644 --- a/tests/nodeenv_test.py +++ b/tests/nodeenv_test.py @@ -3,6 +3,7 @@ import os.path import pipes +import shutil import subprocess import sys import sysconfig @@ -15,12 +16,15 @@ HERE = os.path.abspath(os.path.dirname(__file__)) - -if subprocess.run(["which", "nodejs"],capture_output=True).returncode == 0: - is_nodejs = True -else: - is_nodejs = False - +try: + is_nodejs = shutil.which("nodejs") is not None +except AttributeError: + try: + subprocess.check_call(["which", "nodejs"], stdout=subprocess.PIPE) + except subprocess.CalledProcessError: + is_nodejs = False + else: + is_nodejs = True def call_nodejs(ev_path): assert os.path.exists(ev_path)