Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply formatting to num seconds #489

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tenacity/after.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def after_nothing(retry_state: "RetryCallState") -> None:
def after_log(
logger: "logging.Logger",
log_level: int,
sec_format: str = "%0.3f",
sec_format: str = "%.3g",
) -> typing.Callable[["RetryCallState"], None]:
"""After call strategy that logs to some logger the finished attempt."""

Expand Down
3 changes: 2 additions & 1 deletion tenacity/before_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def before_sleep_log(
logger: "logging.Logger",
log_level: int,
exc_info: bool = False,
sec_format: str = "%.3g",
) -> typing.Callable[["RetryCallState"], None]:
"""Before call strategy that logs to some logger the attempt."""

Expand Down Expand Up @@ -65,7 +66,7 @@ def log_it(retry_state: "RetryCallState") -> None:
logger.log(
log_level,
f"Retrying {fn_name} "
f"in {retry_state.next_action.sleep} seconds as it {verb} {value}.",
f"in {sec_format % retry_state.next_action.sleep} seconds as it {verb} {value}.",
exc_info=local_exc_info,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_after.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_01_default(self):
log = unittest.mock.MagicMock(spec="logging.Logger.log")
logger = unittest.mock.MagicMock(spec="logging.Logger", log=log)

sec_format = "%0.3f"
sec_format = "%.3g"
delay_since_first_attempt = 0.1

retry_state = test_tenacity.make_retry_state(
Expand Down