Skip to content

Commit 2f8edb8

Browse files
committed
Fix warn mode to work when warnings are configured as errors
Previous approach of clearing sys.warnoptions broke when CI used -bb flag, because _args_from_interpreter_flags() expects certain warning options to exist based on sys.flags settings. Instead of clearing completely, filter out only the specific warning options that would convert ImportWarning to errors: - 'error' (converts all warnings) - 'error::ImportWarning' (converts ImportWarning specifically) This preserves options like 'error::BytesWarning' that subprocess's _args_from_interpreter_flags() needs to remove, preventing ValueError.
1 parent 9d8125f commit 2f8edb8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Lib/test/test_multiprocessing_forkserver/test_preload.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ class TestForkserverPreload(unittest.TestCase):
1212

1313
def setUp(self):
1414
self._saved_warnoptions = sys.warnoptions.copy()
15-
sys.warnoptions.clear()
15+
# Remove warning options that would convert ImportWarning to errors:
16+
# - 'error' converts all warnings to errors
17+
# - 'error::ImportWarning' specifically converts ImportWarning
18+
# Keep other specific options like 'error::BytesWarning' that
19+
# subprocess's _args_from_interpreter_flags() expects to remove
20+
sys.warnoptions[:] = [
21+
opt for opt in sys.warnoptions
22+
if opt not in ('error', 'error::ImportWarning')
23+
]
1624
self.ctx = multiprocessing.get_context('forkserver')
1725
forkserver._forkserver._stop()
1826

0 commit comments

Comments
 (0)