From 9c18a083a51d6b3feb659afd2c34c121049b7c25 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 26 Feb 2025 13:49:14 -0500 Subject: [PATCH] Disable tb colors in `._testing.mk_cmd()` Unset the appropriate cpython osenv var such that our `pexpect` script runs in the test suite can maintain original matching logic. --- tractor/_testing/__init__.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tractor/_testing/__init__.py b/tractor/_testing/__init__.py index 1f6624e..43507c3 100644 --- a/tractor/_testing/__init__.py +++ b/tractor/_testing/__init__.py @@ -19,7 +19,10 @@ Various helpers/utils for auditing your `tractor` app and/or the core runtime. ''' -from contextlib import asynccontextmanager as acm +from contextlib import ( + asynccontextmanager as acm, +) +import os import pathlib import tractor @@ -59,7 +62,12 @@ def mk_cmd( exs_subpath: str = 'debugging', ) -> str: ''' - Generate a shell command suitable to pass to ``pexpect.spawn()``. + Generate a shell command suitable to pass to `pexpect.spawn()` + which runs the script as a python program's entrypoint. + + In particular ensure we disable the new tb coloring via unsetting + `$PYTHON_COLORS` so that `pexpect` can pattern match without + color-escape-codes. ''' script_path: pathlib.Path = ( @@ -67,10 +75,15 @@ def mk_cmd( / exs_subpath / f'{ex_name}.py' ) - return ' '.join([ + py_cmd: str = ' '.join([ 'python', str(script_path) ]) + # XXX, required for py 3.13+ + # https://docs.python.org/3/using/cmdline.html#using-on-controlling-color + # https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_COLORS + os.environ['PYTHON_COLORS'] = '0' + return py_cmd @acm