@@ -157,6 +157,15 @@ def test_foo(cov):
157
157
pytest .param ('-n 1' , marks = pytest .mark .skipif ('sys.platform == "win32" and platform.python_implementation() == "PyPy"' ))
158
158
], ids = ['nodist' , 'xdist' ])
159
159
160
+ skipif_multiprocessing_is_broken = pytest .mark .skipif (
161
+ 'sys.version_info[:2] >= (3, 8)' ,
162
+ reason = "deadlocks on Python 3.8+, see: https://bugs.python.org/issue38227"
163
+ )
164
+ method_params = pytest .mark .parametrize ('method' , [
165
+ pytest .param ('fork' , marks = skipif_multiprocessing_is_broken ),
166
+ pytest .param ('spawn' , marks = skipif_multiprocessing_is_broken ),
167
+ ])
168
+
160
169
161
170
@pytest .fixture (scope = 'session' , autouse = True )
162
171
def adjust_sys_path ():
@@ -1025,7 +1034,7 @@ def test_dist_missing_data(testdir):
1025
1034
'--dist=load' ,
1026
1035
'--tx=popen//python=%s' % exe ,
1027
1036
max_worker_restart_0 ,
1028
- script )
1037
+ str ( script ) )
1029
1038
result .stdout .fnmatch_lines ([
1030
1039
'The following workers failed to return coverage data, ensure that pytest-cov is installed on these workers.'
1031
1040
])
@@ -1062,28 +1071,29 @@ def test_funcarg_not_active(testdir):
1062
1071
@pytest .mark .skipif ("sys.version_info[0] < 3" , reason = "no context manager api on Python 2" )
1063
1072
@pytest .mark .skipif ('sys.platform == "win32"' , reason = "multiprocessing support is broken on Windows" )
1064
1073
@pytest .mark .skipif ('platform.python_implementation() == "PyPy"' , reason = "often deadlocks on PyPy" )
1065
- @pytest . mark . skipif ( 'sys.version_info[:2] >= (3, 8)' , reason = "deadlocks on Python 3.8+, see: https://bugs.python.org/issue38227" )
1066
- def test_multiprocessing_pool (testdir ):
1074
+ @method_params
1075
+ def test_multiprocessing_pool (testdir , method ):
1067
1076
pytest .importorskip ('multiprocessing.util' )
1068
1077
1069
1078
script = testdir .makepyfile ('''
1070
1079
import multiprocessing
1071
1080
1072
1081
def target_fn(a):
1073
- %sse : # pragma: nocover
1082
+ {}se : # pragma: nocover
1074
1083
return None
1075
1084
1076
1085
def test_run_target():
1086
+ multiprocessing.set_start_method({!r})
1077
1087
from pytest_cov.embed import cleanup_on_sigterm
1078
1088
cleanup_on_sigterm()
1079
1089
1080
1090
for i in range(33):
1081
1091
with multiprocessing.Pool(3) as p:
1082
1092
p.map(target_fn, [i * 3 + j for j in range(3)])
1083
1093
p.join()
1084
- ''' % '' .join ('''if a == %r:
1094
+ ''' . format ( '' .join ('''if a == %r:
1085
1095
return a
1086
- el''' % i for i in range (99 )))
1096
+ el''' % i for i in range (99 )), method ) )
1087
1097
1088
1098
result = testdir .runpytest ('-v' ,
1089
1099
'--cov=%s' % script .dirpath (),
@@ -1103,18 +1113,19 @@ def test_run_target():
1103
1113
1104
1114
@pytest .mark .skipif ('sys.platform == "win32"' , reason = "multiprocessing support is broken on Windows" )
1105
1115
@pytest .mark .skipif ('platform.python_implementation() == "PyPy"' , reason = "often deadlocks on PyPy" )
1106
- @pytest . mark . skipif ( 'sys.version_info[:2] >= (3, 8)' , reason = "deadlocks on Python 3.8, see: https://bugs.python.org/issue38227" )
1107
- def test_multiprocessing_pool_terminate (testdir ):
1116
+ @method_params
1117
+ def test_multiprocessing_pool_terminate (testdir , method ):
1108
1118
pytest .importorskip ('multiprocessing.util' )
1109
1119
1110
1120
script = testdir .makepyfile ('''
1111
1121
import multiprocessing
1112
1122
1113
1123
def target_fn(a):
1114
- %sse : # pragma: nocover
1124
+ {}se : # pragma: nocover
1115
1125
return None
1116
1126
1117
1127
def test_run_target():
1128
+ multiprocessing.set_start_method({!r})
1118
1129
from pytest_cov.embed import cleanup_on_sigterm
1119
1130
cleanup_on_sigterm()
1120
1131
@@ -1125,9 +1136,9 @@ def test_run_target():
1125
1136
finally:
1126
1137
p.terminate()
1127
1138
p.join()
1128
- ''' % '' .join ('''if a == %r:
1139
+ ''' . format ( '' .join ('''if a == %r:
1129
1140
return a
1130
- el''' % i for i in range (99 )))
1141
+ el''' % i for i in range (99 )), method ) )
1131
1142
1132
1143
result = testdir .runpytest ('-v' ,
1133
1144
'--cov=%s' % script .dirpath (),
@@ -1147,27 +1158,29 @@ def test_run_target():
1147
1158
1148
1159
@pytest .mark .skipif ('sys.platform == "win32"' , reason = "multiprocessing support is broken on Windows" )
1149
1160
@pytest .mark .skipif ('sys.version_info[0] > 2 and platform.python_implementation() == "PyPy"' , reason = "broken on PyPy3" )
1150
- def test_multiprocessing_pool_close (testdir ):
1161
+ @method_params
1162
+ def test_multiprocessing_pool_close (testdir , method ):
1151
1163
pytest .importorskip ('multiprocessing.util' )
1152
1164
1153
1165
script = testdir .makepyfile ('''
1154
1166
import multiprocessing
1155
1167
1156
1168
def target_fn(a):
1157
- %sse : # pragma: nocover
1169
+ {}se : # pragma: nocover
1158
1170
return None
1159
1171
1160
1172
def test_run_target():
1173
+ multiprocessing.set_start_method({!r})
1161
1174
for i in range(33):
1162
1175
p = multiprocessing.Pool(3)
1163
1176
try:
1164
1177
p.map(target_fn, [i * 3 + j for j in range(3)])
1165
1178
finally:
1166
1179
p.close()
1167
1180
p.join()
1168
- ''' % '' .join ('''if a == %r:
1181
+ ''' . format ( '' .join ('''if a == %r:
1169
1182
return a
1170
- el''' % i for i in range (99 )))
1183
+ el''' % i for i in range (99 )), method ) )
1171
1184
1172
1185
result = testdir .runpytest ('-v' ,
1173
1186
'--cov=%s' % script .dirpath (),
@@ -1185,7 +1198,8 @@ def test_run_target():
1185
1198
1186
1199
1187
1200
@pytest .mark .skipif ('sys.platform == "win32"' , reason = "multiprocessing support is broken on Windows" )
1188
- def test_multiprocessing_process (testdir ):
1201
+ @method_params
1202
+ def test_multiprocessing_process (testdir , method ):
1189
1203
pytest .importorskip ('multiprocessing.util' )
1190
1204
1191
1205
script = testdir .makepyfile ('''
@@ -1196,10 +1210,11 @@ def target_fn():
1196
1210
return a
1197
1211
1198
1212
def test_run_target():
1213
+ multiprocessing.set_start_method({!r})
1199
1214
p = multiprocessing.Process(target=target_fn)
1200
1215
p.start()
1201
1216
p.join()
1202
- ''' )
1217
+ ''' . format ( method ) )
1203
1218
1204
1219
result = testdir .runpytest ('-v' ,
1205
1220
'--cov=%s' % script .dirpath (),
@@ -1215,7 +1230,8 @@ def test_run_target():
1215
1230
1216
1231
1217
1232
@pytest .mark .skipif ('sys.platform == "win32"' , reason = "multiprocessing support is broken on Windows" )
1218
- def test_multiprocessing_process_no_source (testdir ):
1233
+ @method_params
1234
+ def test_multiprocessing_process_no_source (testdir , method ):
1219
1235
pytest .importorskip ('multiprocessing.util' )
1220
1236
1221
1237
script = testdir .makepyfile ('''
@@ -1245,7 +1261,8 @@ def test_run_target():
1245
1261
1246
1262
1247
1263
@pytest .mark .skipif ('sys.platform == "win32"' , reason = "multiprocessing support is broken on Windows" )
1248
- def test_multiprocessing_process_with_terminate (testdir ):
1264
+ @method_params
1265
+ def test_multiprocessing_process_with_terminate (testdir , method ):
1249
1266
pytest .importorskip ('multiprocessing.util' )
1250
1267
1251
1268
script = testdir .makepyfile ('''
@@ -1783,6 +1800,7 @@ def test_not_started_plugin_does_not_fail(testdir):
1783
1800
class ns :
1784
1801
cov_source = [True ]
1785
1802
cov_report = ''
1803
+
1786
1804
plugin = pytest_cov .plugin .CovPlugin (ns , None , start = False )
1787
1805
plugin .pytest_runtestloop (None )
1788
1806
plugin .pytest_terminal_summary (None )
@@ -1900,7 +1918,7 @@ def test_append_coverage(testdir, opts, prop):
1900
1918
result = testdir .runpytest ('-v' ,
1901
1919
'--cov=%s' % script .dirpath (),
1902
1920
script ,
1903
- * opts .split ()+ prop .args )
1921
+ * opts .split () + prop .args )
1904
1922
result .stdout .fnmatch_lines ([
1905
1923
'test_1* %s*' % prop .result ,
1906
1924
])
@@ -1909,7 +1927,7 @@ def test_append_coverage(testdir, opts, prop):
1909
1927
'--cov-append' ,
1910
1928
'--cov=%s' % script2 .dirpath (),
1911
1929
script2 ,
1912
- * opts .split ()+ prop .args )
1930
+ * opts .split () + prop .args )
1913
1931
result .stdout .fnmatch_lines ([
1914
1932
'test_1* %s*' % prop .result ,
1915
1933
'test_2* %s*' % prop .result2 ,
0 commit comments