Skip to content

Commit 772a8e1

Browse files
committed
Add test to ensure argparse.exit always raise SystemExit
1 parent 0d22e85 commit 772a8e1

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/test/test_argparse.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def test_invalid_file_only(self):
8989
):
9090
func(file=invalid_f)
9191

92+
def test_exit_when_stderr_oserror(self):
93+
parser = argparse.ArgumentParser()
94+
with (mock.patch('argparse._sys.stderr.write',
95+
side_effect=OSError('not raise this')),
96+
self.assertRaises(SystemExit),
97+
):
98+
parser.exit(status=0, message='foo')
99+
100+
92101
class TestLazyImports(unittest.TestCase):
93102
LAZY_IMPORTS = {
94103
"_colorize",

0 commit comments

Comments
 (0)