1818TIMEOUT_DEFAULT = 10
1919DEBUG = False
2020logger = 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+ )
2126
2227
2328@pytest .yield_fixture (scope = 'module' )
2429def listener (request ):
25- """ Simple module-scoped network listener.
26-
30+ """ Simple module-scoped network listener.
31+
2732 Methods
2833 -------
2934 send(data, timeout): Send data to the listener
@@ -142,7 +147,7 @@ def _process_chunk(self, d, t):
142147 if t is not None :
143148 if DEBUG :
144149 logger .info ('diff %s' % (t - self .clear_time ))
145- if t < self .clear_time :
150+ if t <= self .clear_time :
146151 if DEBUG :
147152 logger .info ('%s < %s' % (t , self .clear_time ))
148153 logger .info ('discarding cleared %s' % d )
@@ -159,11 +164,12 @@ def _process_chunk(self, d, t):
159164 return False
160165
161166 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
164170 d = None
165171 count = 0
166- while d is None and count < MAX_COUNT :
172+ while d is None and count < max_count :
167173
168174 d , t = self .get_data ()
169175 if d is None :
0 commit comments