Skip to content

Commit

Permalink
fix: ModuleNotFound on run cmd (#169)
Browse files Browse the repository at this point in the history
* fix: ModuleNotFound on run cmd

* test: rename test
  • Loading branch information
antazoey authored Nov 4, 2024
1 parent 83663af commit 6a2df5b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion silverback/_click_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,11 @@ def bot_path_callback(ctx: click.Context, param: click.Parameter, path: str | No
try:
return import_from_string(path)
except ImportFromStringError:
return import_from_string(f"bots.{path}")
try:
return import_from_string(f"bots.{path}")
except ModuleNotFoundError:
# This may happen if accidentally running `silverback run`
# with no bots arguments outside of your bots-project directory.
raise click.BadParameter(
"Nothing to run: No bot argument(s) given and no bots module found."
)
14 changes: 13 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
def test_run_no_bots(cli, runner):
result = runner.invoke(cli, "run")
assert result.exit_code != 0
expected = (
"Usage: cli run [OPTIONS] [BOT]\n"
"Try 'cli run --help' for help.\n\n"
"Error: Invalid value for '[BOT]': "
"Nothing to run: No bot argument(s) given and no bots module found.\n"
)
assert result.output == expected


def test_run_verbosity(cli, runner):
"""
A test showing the verbosity option works.
If it didn't work, the exit code would not be 0 here.
"""
result = runner.invoke(cli, ["run", "--help", "--verbosity", "DEBUG"])
result = runner.invoke(cli, ["run", "--help", "--verbosity", "DEBUG"], catch_exceptions=False)
assert result.exit_code == 0

0 comments on commit 6a2df5b

Please sign in to comment.