Skip to content

Commit

Permalink
Apply formatting to num seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
aguinane committed Aug 9, 2024
1 parent e2482a6 commit 5475b69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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 = "%0.3f",
) -> 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
6 changes: 3 additions & 3 deletions tests/test_tenacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ def _before_sleep_log_raises(self, get_call_fn):
logger.removeHandler(handler)

etalon_re = (
r"^Retrying .* in 0\.01 seconds as it raised "
r"^Retrying .* in 0\.010 seconds as it raised "
r"(IO|OS)Error: Hi there, I'm an IOError\.$"
)
self.assertEqual(len(handler.records), 2)
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def test_before_sleep_log_raises_with_exc_info(self):
logger.removeHandler(handler)

etalon_re = re.compile(
r"^Retrying .* in 0\.01 seconds as it raised "
r"^Retrying .* in 0\.010 seconds as it raised "
r"(IO|OS)Error: Hi there, I'm an IOError\.{0}"
r"Traceback \(most recent call last\):{0}"
r".*$".format("\n"),
Expand Down Expand Up @@ -1440,7 +1440,7 @@ def test_before_sleep_log_returns(self, exc_info=False):
finally:
logger.removeHandler(handler)

etalon_re = r"^Retrying .* in 0\.01 seconds as it returned None\.$"
etalon_re = r"^Retrying .* in 0\.010 seconds as it returned None\.$"
self.assertEqual(len(handler.records), 2)
fmt = logging.Formatter().format
self.assertRegex(fmt(handler.records[0]), etalon_re)
Expand Down

0 comments on commit 5475b69

Please sign in to comment.