Skip to content

Commit 003da4a

Browse files
authored
Use formatted stopwatch attributes instead of calling format_* helpers (#4417)
Same thing, but much harder to forget. `Stopwatch` offers the properly formatted versions of timestamps and duration.
1 parent b90bde4 commit 003da4a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tmt/steps/execute/__init__.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
ShellScript,
4747
Stopwatch,
4848
configure_bool_constant,
49-
format_duration,
50-
format_timestamp,
5149
)
5250

5351
if TYPE_CHECKING:
@@ -389,7 +387,7 @@ def _reset_process(
389387
tmt.utils.signals.remove_callback(self.on_interrupt_callback_token)
390388

391389
with Stopwatch() as timer:
392-
self.start_time = format_timestamp(timer.start_time)
390+
self.start_time = timer.start_time_formatted
393391

394392
try:
395393
output = self.guest.execute(
@@ -423,8 +421,8 @@ def _reset_process(
423421
elif tmt.utils.ProcessExitCodes.is_pidfile(self.return_code):
424422
self.logger.warning('Test failed to manage its pidfile.')
425423

426-
self.end_time = format_timestamp(timer.end_time)
427-
self.real_duration = format_duration(timer.duration)
424+
self.end_time = timer.end_time_formatted
425+
self.real_duration = timer.duration_formatted
428426

429427
return output
430428

@@ -919,9 +917,9 @@ def _run_checks_for_test(
919917
for result in check_results:
920918
result.event = event
921919

922-
result.start_time = format_timestamp(timer.start_time)
923-
result.end_time = format_timestamp(timer.end_time)
924-
result.duration = format_duration(timer.duration)
920+
result.start_time = timer.start_time_formatted
921+
result.end_time = timer.end_time_formatted
922+
result.duration = timer.duration_formatted
925923

926924
results += check_results
927925

tmt/utils/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6101,6 +6101,10 @@ def start_time_formatted(self) -> str:
61016101
def end_time_formatted(self) -> str:
61026102
return format_timestamp(self.end_time)
61036103

6104+
@property
6105+
def duration_formatted(self) -> str:
6106+
return format_duration(self.duration)
6107+
61046108
@classmethod
61056109
def measure(
61066110
cls, fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs

0 commit comments

Comments
 (0)