Skip to content

Commit

Permalink
Add some colors to step.py
Browse files Browse the repository at this point in the history
  • Loading branch information
azawlocki committed Aug 31, 2021
1 parent bfd3000 commit a9d745a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions goth/runner/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import time
from typing import Optional, TYPE_CHECKING

import colors

from goth.runner.exceptions import StepTimeoutError

if TYPE_CHECKING:
Expand All @@ -19,14 +21,18 @@ def step(default_timeout: float = 10.0):

def decorator(func):
@functools.wraps(func)
async def wrapper(self: "Probe", *args, timeout: Optional[float] = None):
async def wrapper(
self: "Probe", *args, timeout: Optional[float] = None, **kwargs
):
timeout = timeout if timeout is not None else default_timeout
step_name = f"{self.name}.{func.__name__}(timeout={timeout})"
start_time = time.time()

logger.info("Running step '%s'", step_name)
try:
result = await asyncio.wait_for(func(self, *args), timeout=timeout)
result = await asyncio.wait_for(
func(self, *args, **kwargs), timeout=timeout
)
self.runner.check_assertion_errors()
step_time = time.time() - start_time
logger.debug(
Expand All @@ -37,12 +43,16 @@ async def wrapper(self: "Probe", *args, timeout: Optional[float] = None):
)
except asyncio.TimeoutError:
step_time = time.time() - start_time
logger.error("Step '%s' timed out after %.1f s", step_name, step_time)
logger.error(
colors.red("Step '%s' timed out after %.1f s", style="bold"),
step_name,
step_time,
)
raise StepTimeoutError(step_name, step_time)
except Exception as exc:
step_time = time.time() - start_time
logger.error(
"Step '%s' raised %s in %.1f",
colors.red("Step '%s' raised %s in %.1f", style="bold"),
step_name,
exc.__class__.__name__,
step_time,
Expand Down

0 comments on commit a9d745a

Please sign in to comment.