Skip to content

Commit

Permalink
fix: better fix for already parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 19, 2024
1 parent 0473208 commit 909fde0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/ape/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def set_level(ctx, param, value):
if value.startswith("LOGLEVEL."):
value = value.split(".")[-1].strip()

cli_logger._load_from_sys_argv(default=value)
if cli_logger._did_parse_sys_argv:
cli_logger.set_level(value)
else:
cli_logger._load_from_sys_argv(default=value)

level_names = [lvl.name for lvl in LogLevel]
names_str = f"{', '.join(level_names[:-1])}, or {level_names[-1]}"
Expand Down
4 changes: 0 additions & 4 deletions tests/functional/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_info_level_higher(simple_runner):
def cmd(cli_ctx):
cli_ctx.logger.info("this is a test")

logger._did_parse_sys_argv = False
result = simple_runner.invoke(group_for_testing, ("cmd", "-v", "WARNING"))

# You don't get INFO log when log level is higher
Expand All @@ -58,7 +57,6 @@ def test_warning_level_higher(simple_runner):
def cmd(cli_ctx):
cli_ctx.logger.warning("this is a test")

logger._did_parse_sys_argv = False
result = simple_runner.invoke(group_for_testing, ("cmd", "-v", "ERROR"))
assert "WARNING" not in result.output
assert "this is a test" not in result.output
Expand All @@ -73,7 +71,6 @@ def test_success(simple_runner):
def cmd(cli_ctx):
cli_ctx.logger.success("this is a test")

logger._did_parse_sys_argv = False
result = simple_runner.invoke(group_for_testing, "cmd")
assert "SUCCESS" in result.output
assert "this is a test" in result.output
Expand All @@ -85,7 +82,6 @@ def test_success_level_higher(simple_runner):
def cmd(cli_ctx):
cli_ctx.logger.success("this is a test")

logger._did_parse_sys_argv = False
result = simple_runner.invoke(group_for_testing, ("cmd", "-v", "WARNING"))
assert "SUCCESS" not in result.output
assert "this is a test" not in result.output
Expand Down

0 comments on commit 909fde0

Please sign in to comment.