7
7
import random
8
8
import socket
9
9
import sys
10
+ import warnings
10
11
from io import StringIO
11
12
from pathlib import Path
12
13
15
16
from coverage .sqldata import filename_suffix
16
17
17
18
from .embed import cleanup
19
+ from .plugin import PytestCovWarning
20
+
21
+
22
+ class BrokenCovConfigError (Exception ):
23
+ pass
18
24
19
25
20
26
class _NullFile :
@@ -225,6 +231,10 @@ def summary(self, stream):
225
231
return total
226
232
227
233
234
+ class CentralCovContextWarning (PytestCovWarning ):
235
+ pass
236
+
237
+
228
238
class Central (CovController ):
229
239
"""Implementation for centralised operation."""
230
240
@@ -238,6 +248,13 @@ def start(self):
238
248
data_suffix = _data_suffix ('c' ),
239
249
config_file = self .cov_config ,
240
250
)
251
+ if self .cov .config .dynamic_context == 'test_function' :
252
+ message = (
253
+ 'Detected dynamic_context=test_function in coverage configuration. '
254
+ 'This is unnecessary as this plugin provides the more complete --cov-context option.'
255
+ )
256
+ warnings .warn (CentralCovContextWarning (message ), stacklevel = 1 )
257
+
241
258
self .combining_cov = coverage .Coverage (
242
259
source = self .cov_source ,
243
260
branch = self .cov_branch ,
@@ -269,6 +286,10 @@ def finish(self):
269
286
self .node_descs .add (node_desc )
270
287
271
288
289
+ class DistCovError (Exception ):
290
+ pass
291
+
292
+
272
293
class DistMaster (CovController ):
273
294
"""Implementation for distributed master."""
274
295
@@ -282,6 +303,12 @@ def start(self):
282
303
data_suffix = _data_suffix ('m' ),
283
304
config_file = self .cov_config ,
284
305
)
306
+ if self .cov .config .dynamic_context == 'test_function' :
307
+ raise DistCovError (
308
+ 'Detected dynamic_context=test_function in coverage configuration. '
309
+ 'This is known to cause issues when using xdist, see: https://github.com/pytest-dev/pytest-cov/issues/604\n '
310
+ 'It is recommended to use --cov-context instead.'
311
+ )
285
312
self .cov ._warn_no_data = False
286
313
self .cov ._warn_unimported_source = False
287
314
self .cov ._warn_preimported_source = False
0 commit comments