77import random
88import socket
99import sys
10+ import warnings
1011from io import StringIO
1112from pathlib import Path
1213
1516from coverage .sqldata import filename_suffix
1617
1718from .embed import cleanup
19+ from .plugin import PytestCovWarning
20+
21+
22+ class BrokenCovConfigError (Exception ):
23+ pass
1824
1925
2026class _NullFile :
@@ -225,6 +231,10 @@ def summary(self, stream):
225231 return total
226232
227233
234+ class CentralCovContextWarning (PytestCovWarning ):
235+ pass
236+
237+
228238class Central (CovController ):
229239 """Implementation for centralised operation."""
230240
@@ -238,6 +248,13 @@ def start(self):
238248 data_suffix = _data_suffix ('c' ),
239249 config_file = self .cov_config ,
240250 )
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+
241258 self .combining_cov = coverage .Coverage (
242259 source = self .cov_source ,
243260 branch = self .cov_branch ,
@@ -269,6 +286,10 @@ def finish(self):
269286 self .node_descs .add (node_desc )
270287
271288
289+ class DistCovError (Exception ):
290+ pass
291+
292+
272293class DistMaster (CovController ):
273294 """Implementation for distributed master."""
274295
@@ -282,6 +303,12 @@ def start(self):
282303 data_suffix = _data_suffix ('m' ),
283304 config_file = self .cov_config ,
284305 )
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+ )
285312 self .cov ._warn_no_data = False
286313 self .cov ._warn_unimported_source = False
287314 self .cov ._warn_preimported_source = False
0 commit comments