diff --git a/tests/test_tutorial/test_subcommands/test_tutorial001.py b/tests/test_tutorial/test_subcommands/test_tutorial001.py index 4e8b23ec30..0b40ab7f68 100644 --- a/tests/test_tutorial/test_subcommands/test_tutorial001.py +++ b/tests/test_tutorial/test_subcommands/test_tutorial001.py @@ -87,7 +87,10 @@ def test_scripts(mod): from docs_src.subcommands.tutorial001_py310 import items, users env = os.environ.copy() - env["PYTHONPATH"] = ":".join(list(tutorial001_py310.__path__)) + env["PYTHONPATH"] = ":".join( + list(tutorial001_py310.__path__) + + ([env["PYTHONPATH"]] if "PYTHONPATH" in env else []) + ) for module in [mod, items, users]: result = subprocess.run( diff --git a/tests/test_tutorial/test_subcommands/test_tutorial003.py b/tests/test_tutorial/test_subcommands/test_tutorial003.py index 30b43526fd..756e582bd2 100644 --- a/tests/test_tutorial/test_subcommands/test_tutorial003.py +++ b/tests/test_tutorial/test_subcommands/test_tutorial003.py @@ -166,7 +166,10 @@ def test_scripts(mod): ) env = os.environ.copy() - env["PYTHONPATH"] = ":".join(list(tutorial003_py310.__path__)) + env["PYTHONPATH"] = ":".join( + list(tutorial003_py310.__path__) + + ([env["PYTHONPATH"]] if "PYTHONPATH" in env else []) + ) for module in [mod, items, lands, reigns, towns, users]: result = subprocess.run( diff --git a/tests/test_types_file.py b/tests/test_types_file.py index 3fb7d82f69..734867d373 100644 --- a/tests/test_types_file.py +++ b/tests/test_types_file.py @@ -1,3 +1,4 @@ +import os import subprocess import sys from io import BytesIO, StringIO @@ -9,6 +10,7 @@ from typer._click.utils import PacifyFlushWrapper from typer.testing import CliRunner +import tests from tests.utils import needs_linux, needs_windows app = typer.Typer() @@ -136,6 +138,17 @@ def test_binary_dash() -> None: def test_binary_stderr() -> None: + env = os.environ.copy() + env.update( + { + "PYTHONPATH": ":".join( + [str(Path(tests.__path__[0]).parent)] + [env["PYTHONPATH"]] + ) + } + if "PYTHONPATH" in env + else {} + ) + result = subprocess.run( [ sys.executable, @@ -146,6 +159,7 @@ def test_binary_stderr() -> None: "write-binary-stderr", ], capture_output=True, + env=env, ) assert result.returncode == 0 assert result.stderr == b"binary-stderr\n"