Skip to content

Commit 9bab402

Browse files
authored
Merge pull request #49 from labthings/task-logging-test
unit test for logging
2 parents 6ae5f93 + 0cf548b commit 9bab402

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/test_core_tasks_thread.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import gevent
55
from gevent.thread import get_ident
6+
import time
67

78

89
def test_task_with_args():
@@ -87,18 +88,26 @@ def test_task_log_list():
8788
import logging
8889
import os
8990

91+
logging.getLogger().setLevel("INFO")
92+
9093
def task_func():
9194
logging.warning("Task warning")
95+
for i in range(10):
96+
time.sleep(0.001)
97+
logging.info(f"Counted to {i}")
9298

9399
task_obj = thread.TaskThread(target=task_func)
94100
task_obj.start()
95101
task_obj.started_event.wait()
96102

97-
assert len(task_obj.log) == 1
103+
assert len(task_obj.log) >= 1
98104
assert task_obj.log[0]["message"] == "Task warning"
99105
assert task_obj.log[0]["levelname"] == "WARNING"
100106
assert task_obj.log[0]["filename"] == os.path.basename(__file__)
101107

108+
task_obj.join()
109+
assert len(task_obj.log) == 11, "Didn't get the right number of log entries - are INFO entries being logged?"
110+
102111

103112
def test_task_log_without_thread():
104113

0 commit comments

Comments
 (0)