3
3
import pytest
4
4
import sys
5
5
6
- from xdist .workermanage import WorkerController , unserialize_report
7
- from xdist .remote import serialize_report
6
+ from xdist .workermanage import WorkerController
8
7
import execnet
9
8
import marshal
10
9
@@ -81,187 +80,17 @@ def test_remoteinitconfig(testdir):
81
80
assert config2 .pluginmanager .getplugin ("terminal" ) in (- 1 , None )
82
81
83
82
84
- class TestReportSerialization :
85
- def test_xdist_longrepr_to_str_issue_241 (self , testdir ):
86
- testdir .makepyfile (
87
- """
88
- import os
89
- def test_a(): assert False
90
- def test_b(): pass
91
- """
92
- )
93
- testdir .makeconftest (
94
- """
95
- def pytest_runtest_logreport(report):
96
- print(report.longrepr)
97
- """
98
- )
99
- res = testdir .runpytest ("-n1" , "-s" )
100
- res .stdout .fnmatch_lines (["*1 failed, 1 passed *" ])
101
-
102
- def test_xdist_report_longrepr_reprcrash_130 (self , testdir ):
103
- reprec = testdir .inline_runsource (
104
- """
105
- import py
106
- def test_fail(): assert False, 'Expected Message'
107
- """
108
- )
109
- reports = reprec .getreports ("pytest_runtest_logreport" )
110
- assert len (reports ) == 3
111
- rep = reports [1 ]
112
- added_section = ("Failure Metadata" , str ("metadata metadata" ), "*" )
113
- rep .longrepr .sections .append (added_section )
114
- d = serialize_report (rep )
115
- check_marshallable (d )
116
- a = unserialize_report ("testreport" , d )
117
- # Check assembled == rep
118
- assert a .__dict__ .keys () == rep .__dict__ .keys ()
119
- for key in rep .__dict__ .keys ():
120
- if key != "longrepr" :
121
- assert getattr (a , key ) == getattr (rep , key )
122
- assert rep .longrepr .reprcrash .lineno == a .longrepr .reprcrash .lineno
123
- assert rep .longrepr .reprcrash .message == a .longrepr .reprcrash .message
124
- assert rep .longrepr .reprcrash .path == a .longrepr .reprcrash .path
125
- assert rep .longrepr .reprtraceback .entrysep == a .longrepr .reprtraceback .entrysep
126
- assert (
127
- rep .longrepr .reprtraceback .extraline == a .longrepr .reprtraceback .extraline
128
- )
129
- assert rep .longrepr .reprtraceback .style == a .longrepr .reprtraceback .style
130
- assert rep .longrepr .sections == a .longrepr .sections
131
- # Missing section attribute PR171
132
- assert added_section in a .longrepr .sections
133
-
134
- def test_reprentries_serialization_170 (self , testdir ):
135
- from _pytest ._code .code import ReprEntry
136
-
137
- reprec = testdir .inline_runsource (
138
- """
139
- def test_repr_entry():
140
- x = 0
141
- assert x
142
- """ ,
143
- "--showlocals" ,
144
- )
145
- reports = reprec .getreports ("pytest_runtest_logreport" )
146
- assert len (reports ) == 3
147
- rep = reports [1 ]
148
- d = serialize_report (rep )
149
- a = unserialize_report ("testreport" , d )
150
-
151
- rep_entries = rep .longrepr .reprtraceback .reprentries
152
- a_entries = a .longrepr .reprtraceback .reprentries
153
- for i in range (len (a_entries )):
154
- assert isinstance (rep_entries [i ], ReprEntry )
155
- assert rep_entries [i ].lines == a_entries [i ].lines
156
- assert rep_entries [i ].reprfileloc .lineno == a_entries [i ].reprfileloc .lineno
157
- assert (
158
- rep_entries [i ].reprfileloc .message == a_entries [i ].reprfileloc .message
83
+ class TestWorkerInteractor :
84
+ @pytest .fixture
85
+ def unserialize_report (self , pytestconfig ):
86
+ def unserialize (data ):
87
+ return pytestconfig .hook .pytest_report_from_serializable (
88
+ config = pytestconfig , data = data
159
89
)
160
- assert rep_entries [i ].reprfileloc .path == a_entries [i ].reprfileloc .path
161
- assert rep_entries [i ].reprfuncargs .args == a_entries [i ].reprfuncargs .args
162
- assert rep_entries [i ].reprlocals .lines == a_entries [i ].reprlocals .lines
163
- assert rep_entries [i ].style == a_entries [i ].style
164
90
165
- def test_reprentries_serialization_196 (self , testdir ):
166
- from _pytest ._code .code import ReprEntryNative
91
+ return unserialize
167
92
168
- reprec = testdir .inline_runsource (
169
- """
170
- def test_repr_entry_native():
171
- x = 0
172
- assert x
173
- """ ,
174
- "--tb=native" ,
175
- )
176
- reports = reprec .getreports ("pytest_runtest_logreport" )
177
- assert len (reports ) == 3
178
- rep = reports [1 ]
179
- d = serialize_report (rep )
180
- a = unserialize_report ("testreport" , d )
181
-
182
- rep_entries = rep .longrepr .reprtraceback .reprentries
183
- a_entries = a .longrepr .reprtraceback .reprentries
184
- for i in range (len (a_entries )):
185
- assert isinstance (rep_entries [i ], ReprEntryNative )
186
- assert rep_entries [i ].lines == a_entries [i ].lines
187
-
188
- def test_itemreport_outcomes (self , testdir ):
189
- reprec = testdir .inline_runsource (
190
- """
191
- import py
192
- def test_pass(): pass
193
- def test_fail(): 0/0
194
- @py.test.mark.skipif("True")
195
- def test_skip(): pass
196
- def test_skip_imperative():
197
- py.test.skip("hello")
198
- @py.test.mark.xfail("True")
199
- def test_xfail(): 0/0
200
- def test_xfail_imperative():
201
- py.test.xfail("hello")
202
- """
203
- )
204
- reports = reprec .getreports ("pytest_runtest_logreport" )
205
- assert len (reports ) == 17 # with setup/teardown "passed" reports
206
- for rep in reports :
207
- d = serialize_report (rep )
208
- check_marshallable (d )
209
- newrep = unserialize_report ("testreport" , d )
210
- assert newrep .passed == rep .passed
211
- assert newrep .failed == rep .failed
212
- assert newrep .skipped == rep .skipped
213
- if newrep .skipped and not hasattr (newrep , "wasxfail" ):
214
- assert len (newrep .longrepr ) == 3
215
- assert newrep .outcome == rep .outcome
216
- assert newrep .when == rep .when
217
- assert newrep .keywords == rep .keywords
218
- if rep .failed :
219
- assert newrep .longreprtext == rep .longreprtext
220
-
221
- def test_collectreport_passed (self , testdir ):
222
- reprec = testdir .inline_runsource ("def test_func(): pass" )
223
- reports = reprec .getreports ("pytest_collectreport" )
224
- for rep in reports :
225
- d = serialize_report (rep )
226
- check_marshallable (d )
227
- newrep = unserialize_report ("collectreport" , d )
228
- assert newrep .passed == rep .passed
229
- assert newrep .failed == rep .failed
230
- assert newrep .skipped == rep .skipped
231
-
232
- def test_collectreport_fail (self , testdir ):
233
- reprec = testdir .inline_runsource ("qwe abc" )
234
- reports = reprec .getreports ("pytest_collectreport" )
235
- assert reports
236
- for rep in reports :
237
- d = serialize_report (rep )
238
- check_marshallable (d )
239
- newrep = unserialize_report ("collectreport" , d )
240
- assert newrep .passed == rep .passed
241
- assert newrep .failed == rep .failed
242
- assert newrep .skipped == rep .skipped
243
- if rep .failed :
244
- assert newrep .longrepr == str (rep .longrepr )
245
-
246
- def test_extended_report_deserialization (self , testdir ):
247
- reprec = testdir .inline_runsource ("qwe abc" )
248
- reports = reprec .getreports ("pytest_collectreport" )
249
- assert reports
250
- for rep in reports :
251
- rep .extra = True
252
- d = serialize_report (rep )
253
- check_marshallable (d )
254
- newrep = unserialize_report ("collectreport" , d )
255
- assert newrep .extra
256
- assert newrep .passed == rep .passed
257
- assert newrep .failed == rep .failed
258
- assert newrep .skipped == rep .skipped
259
- if rep .failed :
260
- assert newrep .longrepr == str (rep .longrepr )
261
-
262
-
263
- class TestWorkerInteractor :
264
- def test_basic_collect_and_runtests (self , worker ):
93
+ def test_basic_collect_and_runtests (self , worker , unserialize_report ):
265
94
worker .testdir .makepyfile (
266
95
"""
267
96
def test_func():
@@ -286,14 +115,14 @@ def test_func():
286
115
ev = worker .popevent ("testreport" ) # setup
287
116
ev = worker .popevent ("testreport" )
288
117
assert ev .name == "testreport"
289
- rep = unserialize_report (ev .name , ev . kwargs ["data" ])
118
+ rep = unserialize_report (ev .kwargs ["data" ])
290
119
assert rep .nodeid .endswith ("::test_func" )
291
120
assert rep .passed
292
121
assert rep .when == "call"
293
122
ev = worker .popevent ("workerfinished" )
294
123
assert "workeroutput" in ev .kwargs
295
124
296
- def test_remote_collect_skip (self , worker ):
125
+ def test_remote_collect_skip (self , worker , unserialize_report ):
297
126
worker .testdir .makepyfile (
298
127
"""
299
128
import pytest
@@ -305,25 +134,25 @@ def test_remote_collect_skip(self, worker):
305
134
assert not ev .kwargs
306
135
ev = worker .popevent ()
307
136
assert ev .name == "collectreport"
308
- rep = unserialize_report (ev .name , ev . kwargs ["data" ])
137
+ rep = unserialize_report (ev .kwargs ["data" ])
309
138
assert rep .skipped
310
139
assert rep .longrepr [2 ] == "Skipped: hello"
311
140
ev = worker .popevent ("collectionfinish" )
312
141
assert not ev .kwargs ["ids" ]
313
142
314
- def test_remote_collect_fail (self , worker ):
143
+ def test_remote_collect_fail (self , worker , unserialize_report ):
315
144
worker .testdir .makepyfile ("""aasd qwe""" )
316
145
worker .setup ()
317
146
ev = worker .popevent ("collectionstart" )
318
147
assert not ev .kwargs
319
148
ev = worker .popevent ()
320
149
assert ev .name == "collectreport"
321
- rep = unserialize_report (ev .name , ev . kwargs ["data" ])
150
+ rep = unserialize_report (ev .kwargs ["data" ])
322
151
assert rep .failed
323
152
ev = worker .popevent ("collectionfinish" )
324
153
assert not ev .kwargs ["ids" ]
325
154
326
- def test_runtests_all (self , worker ):
155
+ def test_runtests_all (self , worker , unserialize_report ):
327
156
worker .testdir .makepyfile (
328
157
"""
329
158
def test_func(): pass
@@ -345,7 +174,7 @@ def test_func2(): pass
345
174
for i in range (3 ): # setup/call/teardown
346
175
ev = worker .popevent ("testreport" )
347
176
assert ev .name == "testreport"
348
- rep = unserialize_report (ev .name , ev . kwargs ["data" ])
177
+ rep = unserialize_report (ev .kwargs ["data" ])
349
178
assert rep .nodeid .endswith (func )
350
179
ev = worker .popevent ("workerfinished" )
351
180
assert "workeroutput" in ev .kwargs
0 commit comments