From 52f488d1b0e0c961686ce9e7b426a891dd45bbfa Mon Sep 17 00:00:00 2001 From: Matthias Bach Date: Mon, 7 Nov 2022 18:53:34 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=E2=80=8D=E2=99=82=EF=B8=8F=20Ensur?= =?UTF-8?q?e=20the=20`PYTHONPATH`=20is=20set=20properly=20when=20testing?= =?UTF-8?q?=20the=20tutorial=20scripts=20(#407)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_tutorial/test_subcommands/test_tutorial001.py | 5 +++++ tests/test_tutorial/test_subcommands/test_tutorial003.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/test_tutorial/test_subcommands/test_tutorial001.py b/tests/test_tutorial/test_subcommands/test_tutorial001.py index 5e1d1b465..b8da25ec1 100644 --- a/tests/test_tutorial/test_subcommands/test_tutorial001.py +++ b/tests/test_tutorial/test_subcommands/test_tutorial001.py @@ -1,3 +1,4 @@ +import os import subprocess import pytest @@ -84,11 +85,15 @@ def test_users_delete(app): def test_scripts(mod): from docs_src.subcommands.tutorial001 import items, users + env = os.environ.copy() + env["PYTHONPATH"] = ":".join(list(tutorial001.__path__)) + for module in [mod, items, users]: result = subprocess.run( ["coverage", "run", module.__file__, "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8", + env=env, ) assert "Usage" in result.stdout diff --git a/tests/test_tutorial/test_subcommands/test_tutorial003.py b/tests/test_tutorial/test_subcommands/test_tutorial003.py index 770da9712..1edf8c1e4 100644 --- a/tests/test_tutorial/test_subcommands/test_tutorial003.py +++ b/tests/test_tutorial/test_subcommands/test_tutorial003.py @@ -1,3 +1,4 @@ +import os import subprocess import pytest @@ -157,11 +158,15 @@ def test_lands_towns_burn(app): def test_scripts(mod): from docs_src.subcommands.tutorial003 import items, lands, reigns, towns, users + env = os.environ.copy() + env["PYTHONPATH"] = ":".join(list(tutorial003.__path__)) + for module in [mod, items, lands, reigns, towns, users]: result = subprocess.run( ["coverage", "run", module.__file__, "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8", + env=env, ) assert "Usage" in result.stdout