7
7
"""
8
8
9
9
import contextlib
10
+ import enum
10
11
import os
11
12
import sys
12
13
import time
@@ -57,10 +58,12 @@ def worker_title(title):
57
58
pass
58
59
59
60
60
- class WorkerInteractor :
61
- SHUTDOWN_MARK = object ()
62
- QUEUE_REPLACED_MARK = object ()
61
+ class Marker (enum .Enum ):
62
+ SHUTDOWN = 0
63
+ QUEUE_REPLACED = 1
64
+
63
65
66
+ class WorkerInteractor :
64
67
def __init__ (self , config , channel ):
65
68
self .config = config
66
69
self .workerid = config .workerinput .get ("workerid" , "?" )
@@ -79,7 +82,7 @@ def _get_next_item_index(self):
79
82
is replaced concurrently in another thread.
80
83
"""
81
84
result = self .torun .get ()
82
- while result is self . QUEUE_REPLACED_MARK :
85
+ while result is Marker . QUEUE_REPLACED :
83
86
result = self .torun .get ()
84
87
return result
85
88
@@ -114,8 +117,8 @@ def pytest_collection(self, session):
114
117
self .sendevent ("collectionstart" )
115
118
116
119
def handle_command (self , command ):
117
- if command is self . SHUTDOWN_MARK :
118
- self .torun .put (self . SHUTDOWN_MARK )
120
+ if command is Marker . SHUTDOWN :
121
+ self .torun .put (Marker . SHUTDOWN )
119
122
return
120
123
121
124
name , kwargs = command
@@ -128,7 +131,7 @@ def handle_command(self, command):
128
131
for i in range (len (self .session .items )):
129
132
self .torun .put (i )
130
133
elif name == "shutdown" :
131
- self .torun .put (self . SHUTDOWN_MARK )
134
+ self .torun .put (Marker . SHUTDOWN )
132
135
elif name == "steal" :
133
136
self .steal (kwargs ["indices" ])
134
137
@@ -149,14 +152,14 @@ def old_queue_get_nowait_noraise():
149
152
self .torun .put (i )
150
153
151
154
self .sendevent ("unscheduled" , indices = stolen )
152
- old_queue .put (self . QUEUE_REPLACED_MARK )
155
+ old_queue .put (Marker . QUEUE_REPLACED )
153
156
154
157
@pytest .hookimpl
155
158
def pytest_runtestloop (self , session ):
156
159
self .log ("entering main loop" )
157
- self .channel .setcallback (self .handle_command , endmarker = self . SHUTDOWN_MARK )
160
+ self .channel .setcallback (self .handle_command , endmarker = Marker . SHUTDOWN )
158
161
self .nextitem_index = self ._get_next_item_index ()
159
- while self .nextitem_index is not self . SHUTDOWN_MARK :
162
+ while self .nextitem_index is not Marker . SHUTDOWN :
160
163
self .run_one_test ()
161
164
if session .shouldfail or session .shouldstop :
162
165
break
@@ -168,7 +171,7 @@ def run_one_test(self):
168
171
169
172
items = self .session .items
170
173
item = items [self .item_index ]
171
- if self .nextitem_index is self . SHUTDOWN_MARK :
174
+ if self .nextitem_index is Marker . SHUTDOWN :
172
175
nextitem = None
173
176
else :
174
177
nextitem = items [self .nextitem_index ]
0 commit comments