From 6f6842ef66a3bb8272ada6caf468de28ab6caaa3 Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:00:46 +0000 Subject: [PATCH] test_scripts: run scripts from the active interpreter instead of PATH --- test/test_scripts.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/test/test_scripts.py b/test/test_scripts.py index c1a6c082d..dc7315798 100644 --- a/test/test_scripts.py +++ b/test/test_scripts.py @@ -5,12 +5,20 @@ """ import errno +import shutil import subprocess import sys +import sysconfig import unittest from abc import ABCMeta, abstractmethod -from .config import * + +def _console_script(name: str) -> str: + """Return the path of the console script ``name`` installed with this interpreter.""" + path = shutil.which(name, path=sysconfig.get_path("scripts")) + if path is None: + raise FileNotFoundError(f"console script {name!r} is not installed") + return path class CanScriptTest(unittest.TestCase, metaclass=ABCMeta): @@ -28,10 +36,9 @@ def test_do_commands_exist(self): for command in self._commands(): try: subprocess.check_output( - command.split(), + command, stderr=subprocess.STDOUT, encoding="utf-8", - shell=IS_WINDOWS, ) except subprocess.CalledProcessError as e: return_code = e.returncode @@ -73,8 +80,8 @@ def _import(self): class TestLoggerScript(CanScriptTest): def _commands(self): commands = [ - "python -m can.logger --help", - "can_logger --help", + [sys.executable, "-m", "can.logger", "--help"], + [_console_script("can_logger"), "--help"], ] return commands @@ -87,8 +94,8 @@ def _import(self): class TestPlayerScript(CanScriptTest): def _commands(self): commands = [ - "python -m can.player --help", - "can_player --help", + [sys.executable, "-m", "can.player", "--help"], + [_console_script("can_player"), "--help"], ] return commands @@ -101,8 +108,8 @@ def _import(self): class TestBridgeScript(CanScriptTest): def _commands(self): commands = [ - "python -m can.bridge --help", - "can_bridge --help", + [sys.executable, "-m", "can.bridge", "--help"], + [_console_script("can_bridge"), "--help"], ] return commands @@ -115,8 +122,8 @@ def _import(self): class TestLogconvertScript(CanScriptTest): def _commands(self): commands = [ - "python -m can.logconvert --help", - "can_logconvert --help", + [sys.executable, "-m", "can.logconvert", "--help"], + [_console_script("can_logconvert"), "--help"], ] return commands