@@ -129,8 +129,29 @@ def pytest_sessionstart(self, session):
129
129
self ._start_time = time .time ()
130
130
131
131
def pytest_collectreport (self , report ):
132
- if not self ._must_omit ('collectors' ):
133
- self ._json_collectors .append (serialize .make_collector (report ))
132
+ if self ._must_omit ('collectors' ):
133
+ return
134
+ json_result = []
135
+ for item in report .result :
136
+ json_item = serialize .make_collectitem (item )
137
+ item ._json_collectitem = json_item
138
+ json_result .append (json_item )
139
+ self ._json_collectors .append (serialize .make_collector (report ,
140
+ json_result ))
141
+
142
+ def pytest_deselected (self , items ):
143
+ if self ._must_omit ('collectors' ):
144
+ return
145
+ for item in items :
146
+ item ._json_collectitem ['deselected' ] = True
147
+
148
+ @pytest .hookimpl (hookwrapper = True )
149
+ def pytest_collection_modifyitems (self , items ):
150
+ yield
151
+ if self ._must_omit ('collectors' ):
152
+ return
153
+ for item in items :
154
+ del item ._json_collectitem
134
155
135
156
def pytest_runtest_logreport (self , report ):
136
157
nodeid = report .nodeid
@@ -183,7 +204,8 @@ def pytest_sessionfinish(self, session):
183
204
exitcode = session .exitstatus ,
184
205
root = str (session .fspath ),
185
206
environment = getattr (self ._config , '_metadata' , {}),
186
- summary = serialize .make_summary (self ._json_tests ),
207
+ summary = serialize .make_summary (self ._json_tests ,
208
+ collected = session .testscollected ),
187
209
)
188
210
if not self ._config .option .json_report_summary :
189
211
if self ._json_collectors :
@@ -215,7 +237,7 @@ def save_report(self, path):
215
237
os .makedirs (dirname )
216
238
# Mimick FileExistsError for py2.7 compatibility
217
239
except OSError as e :
218
- import errno
240
+ import errno # pylint: disable=import-outside-toplevel
219
241
if e .errno != errno .EEXIST :
220
242
raise
221
243
with open (path , 'w' ) as f :
0 commit comments