From dd260b0a88217f5cc590a407c859f0ff702032ae Mon Sep 17 00:00:00 2001 From: William Bergamin Date: Tue, 23 Jul 2024 10:03:24 -0400 Subject: [PATCH] use run_path instead of run module --- tests/scenario_test/test_get_hooks.py | 9 +++------ tests/scenario_test/test_get_manifest.py | 9 +++------ tests/scenario_test/test_start.py | 11 ++++------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/scenario_test/test_get_hooks.py b/tests/scenario_test/test_get_hooks.py index 608fbc5..46ef70c 100644 --- a/tests/scenario_test/test_get_hooks.py +++ b/tests/scenario_test/test_get_hooks.py @@ -9,18 +9,15 @@ class TestGetHooks: def setup_method(self): - cli_args = [get_hooks.__name__, "--protocol", "message-boundaries", "--boundary", ""] + cli_args = [get_hooks.__file__, "--protocol", "message-boundaries", "--boundary", ""] self.argv_mock = patch.object(sys, "argv", cli_args) self.argv_mock.start() - # Prevent unpredictable behavior from import order mismatch - if get_hooks.__name__ in sys.modules: - del sys.modules[get_hooks.__name__] def teardown_method(self): self.argv_mock.stop() def test_get_manifest(self, capsys): - runpy.run_module(get_hooks.__name__, run_name="__main__") + runpy.run_path(get_hooks.__file__, run_name="__main__") out, err = capsys.readouterr() json_response = json.loads(out) @@ -29,7 +26,7 @@ def test_get_manifest(self, capsys): assert get_manifest.__name__ in json_response["hooks"]["get-manifest"] def test_start(self, capsys): - runpy.run_module(get_hooks.__name__, run_name="__main__") + runpy.run_path(get_hooks.__file__, run_name="__main__") out, err = capsys.readouterr() json_response = json.loads(out) diff --git a/tests/scenario_test/test_get_manifest.py b/tests/scenario_test/test_get_manifest.py index 21d10fa..0cfa4c6 100644 --- a/tests/scenario_test/test_get_manifest.py +++ b/tests/scenario_test/test_get_manifest.py @@ -13,13 +13,10 @@ class TestGetManifest: def setup_method(self): - cli_args = [get_manifest.__name__, "--protocol", "message-boundaries", "--boundary", ""] + cli_args = [get_manifest.__file__, "--protocol", "message-boundaries", "--boundary", ""] self.argv_mock = patch.object(sys, "argv", cli_args) self.argv_mock.start() self.cwd = os.getcwd() - # Prevent unpredictable behavior from import order mismatch - if get_manifest.__name__ in sys.modules: - del sys.modules[get_manifest.__name__] def teardown_method(self): os.chdir(self.cwd) @@ -29,7 +26,7 @@ def test_get_manifest_script(self, capsys): working_directory = "tests/scenario_test/test_app" os.chdir(working_directory) - runpy.run_module(get_manifest.__name__, run_name="__main__") + runpy.run_path(get_manifest.__file__, run_name="__main__") out, err = capsys.readouterr() assert err == "" @@ -40,6 +37,6 @@ def test_get_manifest_script_no_manifest(self): os.chdir(working_directory) with pytest.raises(CliError) as e: - runpy.run_module(get_manifest.__name__, run_name="__main__") + runpy.run_path(get_manifest.__file__, run_name="__main__") assert str(e.value) == "Could not find a manifest.json file" diff --git a/tests/scenario_test/test_start.py b/tests/scenario_test/test_start.py index 75f43e4..4a3a1b1 100644 --- a/tests/scenario_test/test_start.py +++ b/tests/scenario_test/test_start.py @@ -22,14 +22,11 @@ def setup_method(self): setup_mock_web_api_server(self) start_socket_mode_server(self, 3012) - cli_args = [start.__name__, "--protocol", "message-boundaries", "--boundary", ""] + cli_args = [start.__file__, "--protocol", "message-boundaries", "--boundary", ""] self.argv_mock = patch.object(sys, "argv", cli_args) self.argv_mock.start() self.cwd = os.getcwd() - # Prevent unpredictable behavior from import order mismatch - if start.__name__ in sys.modules: - del sys.modules[start.__name__] def teardown_method(self): self.argv_mock.stop() @@ -44,7 +41,7 @@ def teardown_method(self): def test_start_script(self, capsys, caplog): os.chdir(self.working_directory) - runpy.run_module(start.__name__, run_name="__main__") + runpy.run_path(start.__file__, run_name="__main__") captured_sys = capsys.readouterr() @@ -55,7 +52,7 @@ def test_start_with_entrypoint(self, capsys, caplog): os.environ["SLACK_APP_PATH"] = "my_app.py" os.chdir(self.working_directory) - runpy.run_module(start.__name__, run_name="__main__") + runpy.run_path(start.__file__, run_name="__main__") captured_sys = capsys.readouterr() @@ -67,6 +64,6 @@ def test_start_no_entrypoint(self): os.chdir(working_directory) with pytest.raises(CliError) as e: - runpy.run_module(start.__name__, run_name="__main__") + runpy.run_path(start.__file__, run_name="__main__") assert "Could not find app.py file" in str(e.value)