Sto usando unittest per affermare che il mio script solleva il codice corretto SystemExit
.Unittest: assertare codice SystemExit
sull'esempio da http://docs.python.org/3.3/library/unittest.html#unittest.TestCase.assertRaises
with self.assertRaises(SomeException) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
ho codificato questo:
with self.assertRaises(SystemExit) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
Tuttavia, questo non funziona. Il errore seguente esce:
AttributeError: 'SystemExit' object has no attribute 'error_code'