5
unittestを使用して、スクリプトで正しいコードがSystemExit
になることをアサートします。Unittest:SystemExitコードを正しくアサートする
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)
からの例に基づいて、私はこれをコード化:
with self.assertRaises(SystemExit) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
しかし、これは動作しません。次エラーがアップします:
AttributeError: 'SystemExit' object has no attribute 'error_code'