单元测试导致 sys.exit() [英] Unittest causing sys.exit()

查看:39
本文介绍了单元测试导致 sys.exit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不管我做什么 sys.exit() 都会被 unittest 调用,即使是最微不足道的例子.我不知道是我的安装搞砸了还是发生了什么.

No matter what I do sys.exit() is called by unittest, even the most trivial examples. I can't tell if my install is messed up or what is going on.

IDLE 1.2.2      ==== No Subprocess ====
>>> import unittest
>>> 
>>> class Test(unittest.TestCase):
        def testA(self):
            a = 1
            self.assertEqual(a,1)

>>> unittest.main()
option -n not recognized
Usage: idle.pyw [options] [test] [...]

Options:
  -h, --help       Show this message
  -v, --verbose    Verbose output
  -q, --quiet      Minimal output

 Examples:
   idle.pyw                               - run default set of tests
   idle.pyw MyTestSuite                   - run suite 'MyTestSuite'
   idle.pyw MyTestCase.testSomething      - run MyTestCase.testSomething
   idle.pyw MyTestCase                    - run all 'test*' test methods
                                           in MyTestCase

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    unittest.main()
  File "E:\Python25\lib\unittest.py", line 767, in __init__
    self.parseArgs(argv)
  File "E:\Python25\lib\unittest.py", line 796, in parseArgs
    self.usageExit(msg)
  File "E:\Python25\lib\unittest.py", line 773, in usageExit
    sys.exit(2)
SystemExit: 2
>>> 

推荐答案

您的示例也在我的安装中退出.我可以通过更改使其执行测试并留在 Python 中

Your example is exiting on my install too. I can make it execute the tests and stay within Python by changing

unittest.main()

unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(Test))

在 Python 库参考中此处提供了更多信息.

More information is available here in the Python Library Reference.

这篇关于单元测试导致 sys.exit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆