Close #20500: Don't trigger PyObject_Str assertion at shutdown

This commit is contained in:
Nick Coghlan 2014-02-09 10:43:21 +10:00
parent c9d1a6b85e
commit d979e4335d
4 changed files with 28 additions and 2 deletions

View file

@ -405,6 +405,24 @@ class CmdLineTest(unittest.TestCase):
'stdout=%r stderr=%r' % (stdout, stderr))
self.assertEqual(0, rc)
def test_issue20500_exit_with_exception_value(self):
script = textwrap.dedent("""\
import sys
error = None
try:
raise ValueError('some text')
except ValueError as err:
error = err
if error:
sys.exit(error)
""")
with temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
exitcode, stdout, stderr = assert_python_failure(script_name)
text = stderr.decode('ascii')
self.assertEqual(text, "some text")
def test_main():
support.run_unittest(CmdLineTest)