@@ -493,7 +493,7 @@ def test_redirect_stdout_unwrapped_after_keyboard_interrupt() -> None:
493493 # #212: when redirect_stdout wraps sys.stdout and iteration is abandoned
494494 # by a KeyboardInterrupt, the bar must unwrap stdout again. Runs in a
495495 # subprocess because stream wrapping mutates process-global sys.stdout.
496- child = textwrap .dedent (
496+ child : str = textwrap .dedent (
497497 """
498498 import sys
499499 import progressbar
@@ -510,8 +510,13 @@ def test_redirect_stdout_unwrapped_after_keyboard_interrupt() -> None:
510510 sys.exit(2 if isinstance(sys.stdout, WrappingIO) else 0)
511511 """
512512 )
513- result = subprocess .run (
514- [sys .executable , '-c' , child ], capture_output = True , text = True
513+ env : dict [str , str ] = os .environ .copy ()
514+ env ['PYTHONPATH' ] = os .pathsep .join (sys .path )
515+ result : subprocess .CompletedProcess [str ] = subprocess .run (
516+ [sys .executable , '-c' , child ],
517+ capture_output = True ,
518+ text = True ,
519+ env = env ,
515520 )
516521 assert result .returncode == 0 , (
517522 f'stdout left wrapped after interrupt; rc={ result .returncode } \n '
@@ -523,9 +528,7 @@ def test_wrap_logging_deduplicates_shared_handler(monkeypatch) -> None:
523528 # A handler attached to more than one logger must be wrapped only once.
524529 # _iter_loggers yields the root logger then named loggers, so a handler
525530 # shared by both is seen twice and the second visit is skipped.
526- for _ in range (5 ):
527- progressbar .streams .unwrap (stderr = True , stdout = True )
528- progressbar .streams .unwrap_logging ()
531+ reset_wrapped_streams ()
529532
530533 stream = io .StringIO ()
531534 monkeypatch .setattr (sys , 'stderr' , stream )
0 commit comments