python unit test to assert a method calls sys.exit()

来源:互联网 发布:商品与条形码数据库 编辑:程序博客网 时间:2024/04/29 19:40

python2.6:

with self.assertRaises(SystemExit, func) as cm:    your_method()self.assertEqual(cm.exception.error_code, 1)


>python 2.7:

with self.assertRaisesRegexp(SystemExit, '1'):    your_method()