Skip to content

Commit

Permalink
use run_path instead of run module
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamBergamin committed Jul 23, 2024
1 parent d25bed0 commit dd260b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
9 changes: 3 additions & 6 deletions tests/scenario_test/test_get_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions tests/scenario_test/test_get_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 == ""
Expand All @@ -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"
11 changes: 4 additions & 7 deletions tests/scenario_test/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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)

0 comments on commit dd260b0

Please sign in to comment.