Skip to content

Commit 879f929

Browse files
committed
pytest-listener: Fix flakiness on windows-py39+ due to receive() happening on the same timestamp as a CLEAR is received.
1 parent 5480ab9 commit 879f929

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pytest-listener/pytest_listener.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
TIMEOUT_DEFAULT = 10
1919
DEBUG = False
2020
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+
)
2126

2227

2328
@pytest.yield_fixture(scope='module')
2429
def 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy