diff --git a/src/helpers.py b/src/helpers.py index 8a50b0e723d28652e1eb7e27c53636b506774b74..ab6799057145550f4346e05f29aba7741da03989 100644 --- a/src/helpers.py +++ b/src/helpers.py @@ -49,9 +49,10 @@ class TimeTracking(object): method. Duration can always be shown by printing the time tracking object or calling get_current_duration. """ - def __init__(self, start=True): + def __init__(self, start=True, name="undefined job"): self.start = None self.end = None + self._name = name if start: self._start() @@ -93,7 +94,7 @@ class TimeTracking(object): def __exit__(self, exc_type, exc_val, exc_tb): self.stop() - logging.info(f"undefined job finished after {self}") + logging.info(f"{self._name} finished after {self}") def prepare_host(create_new=True, sampling="daily"): diff --git a/test/test_helpers.py b/test/test_helpers.py index b807d2b8612b9ee006bff43f1ae4cfcfd2dd07e1..07ec244e078f977dca761274260275aab355c183 100644 --- a/test/test_helpers.py +++ b/test/test_helpers.py @@ -117,6 +117,14 @@ class TestTimeTracking: expression = PyTestRegex(r"undefined job finished after \d+:\d+:\d+ \(hh:mm:ss\)") assert caplog.record_tuples[-1] == ('root', 20, expression) + def test_name_enter_exit(self, caplog): + caplog.set_level(logging.INFO) + with TimeTracking(name="my job") as t: + assert t.start is not None + assert t.end is None + expression = PyTestRegex(r"my job finished after \d+:\d+:\d+ \(hh:mm:ss\)") + assert caplog.record_tuples[-1] == ('root', 20, expression) + class TestPrepareHost: