diff --git a/examples/debugging/sync_bp.py b/examples/debugging/sync_bp.py index a26a9c54..64a6e14b 100644 --- a/examples/debugging/sync_bp.py +++ b/examples/debugging/sync_bp.py @@ -1,9 +1,22 @@ from functools import partial +import os import time +# ?TODO? how to make `pdbp` enforce this? +# os.environ['PYTHON_COLORS'] = '0' +# os.environ['NO_COLOR'] = '1' + import trio import tractor +# disable `pbdp` prompt colors +# for prompt matching in test. +def disable_pdbp_color(): + if os.environ['PYTHON_COLORS'] == '0': + from tractor.devx.debug import _repl + _repl.TractorConfig.use_pygments = False + + # TODO: only import these when not running from test harness? # can we detect `pexpect` usage maybe? # from tractor.devx.debug import ( @@ -42,6 +55,7 @@ async def start_n_sync_pause( ctx: tractor.Context, ): actor: tractor.Actor = tractor.current_actor() + disable_pdbp_color() # sync to parent-side task await ctx.started() @@ -52,13 +66,15 @@ async def start_n_sync_pause( async def main() -> None: + disable_pdbp_color() async with ( tractor.open_nursery( debug_mode=True, maybe_enable_greenback=True, - enable_stack_on_sig=True, - # loglevel='warning', - # loglevel='devx', + + # XXX flags required for test pattern matching. + loglevel='pdb', + # enable_stack_on_sig=True, ) as an, trio.open_nursery() as tn, ): @@ -68,8 +84,8 @@ async def main() -> None: p: tractor.Portal = await an.start_actor( 'subactor', enable_modules=[__name__], - # infect_asyncio=True, debug_mode=True, + # infect_asyncio=True, ) # TODO: 3 sub-actor usage cases: diff --git a/tests/devx/conftest.py b/tests/devx/conftest.py index 12e3ce04..2c621f41 100644 --- a/tests/devx/conftest.py +++ b/tests/devx/conftest.py @@ -95,6 +95,8 @@ def spawn( os.environ['PYTHON_COLORS'] = '0' # disable all ANSI color output # os.environ['NO_COLOR'] = '1' + # ?TODO, doesn't seem to disable prompt color + # for `pdbp`? def set_spawn_method( start_method: str, diff --git a/tests/devx/test_pause_from_non_trio.py b/tests/devx/test_pause_from_non_trio.py index 2288653f..0710ba80 100644 --- a/tests/devx/test_pause_from_non_trio.py +++ b/tests/devx/test_pause_from_non_trio.py @@ -66,19 +66,28 @@ def test_pause_from_sync( # XXX required for `breakpoint()` overload and # thus`tractor.devx.pause_from_sync()`. pytest.importorskip('greenback') - child = spawn('sync_bp') + child = spawn( + 'sync_bp', + loglevel='pdb', # XXX pattern matching + ) # first `sync_pause()` after nurseries open child.expect(PROMPT) - assert_before( + _before: str = assert_before( child, [ - # pre-prompt line - _pause_msg, - "\n\n' + ')>\n' ) @classmethod @@ -282,7 +282,7 @@ class Lock: ): message += ( '-> No new task holds the TTY lock!\n\n' - f'{Lock.repr()}\n' + f'{Lock.repr()}' ) elif (