18
18
TIMEOUT_DEFAULT = 10
19
19
DEBUG = False
20
20
logger = logging .getLogger ('pytest-listener' )
21
+ logging .basicConfig (
22
+ level = logging .INFO ,
23
+ format = '%(asctime)s | %(levelname)-8s | %(name)s | %(message)s' ,
24
+ datefmt = '%Y-%m-%d %H:%M:%S' ,
25
+ )
21
26
22
27
23
28
@pytest .yield_fixture (scope = 'module' )
24
29
def listener (request ):
25
- """ Simple module-scoped network listener.
26
-
30
+ """ Simple module-scoped network listener.
31
+
27
32
Methods
28
33
-------
29
34
send(data, timeout): Send data to the listener
@@ -142,7 +147,7 @@ def _process_chunk(self, d, t):
142
147
if t is not None :
143
148
if DEBUG :
144
149
logger .info ('diff %s' % (t - self .clear_time ))
145
- if t < self .clear_time :
150
+ if t <= self .clear_time :
146
151
if DEBUG :
147
152
logger .info ('%s < %s' % (t , self .clear_time ))
148
153
logger .info ('discarding cleared %s' % d )
@@ -159,11 +164,12 @@ def _process_chunk(self, d, t):
159
164
return False
160
165
161
166
def receive (self , timeout = TIMEOUT_DEFAULT ):
162
- if timeout is not None :
163
- MAX_COUNT = int (timeout ) * 10
167
+ if timeout is None :
168
+ raise ValueError ("timeout cannot be None" )
169
+ max_count = int (timeout ) * 10
164
170
d = None
165
171
count = 0
166
- while d is None and count < MAX_COUNT :
172
+ while d is None and count < max_count :
167
173
168
174
d , t = self .get_data ()
169
175
if d is None :
0 commit comments