py.test报告indexError/keyError作为故障而不是错误


 import unittest
 import logging
 FORMAT = '%(asctime)-15s %(message)s'
 logging.basicConfig(format=FORMAT)

 log = logging.getLogger(__name__)
 log.root.setLevel(logging.DEBUG)
 class FixturesTest(unittest.TestCase):
     def setUp(self):
         log.info('starting setup')
         self.fixture = range(1, 10)
         log.warn('Hello world')
     def tearDown(self):
         log.info('starting teardown')
         del self.fixture
         log.info('Goodbye world')
     def test_pass(self):
         log.info('in test pass')
         self.assertEqual(self.fixture, range(1, 10))
         log.error('Test world')
     def test_fail(self):
         log.info('in test fail')
         log.error("let's fail a test")
         assert(1==0)
     def test_error(self):
         log.info('in test error')
         log.info("let's error a test")
         d = []
         d[1]
     if __name__ == '__main__':
         unittest.main()

使用py.test运行上述代码,它报告了Test_error测试方法作为测试故障而不是测试错误。尽管使用Unitest进行运行将其显示为错误而不是失败,但您可以分享对此的任何想法吗?

更新:相同的代码,鼻子也将其视为错误而不是test_error失败,这是py.test中的问题吗?

更新:如果您不确定我所指的是什么,如果您运行py.test test_filename.py,如果您运行python -m Unittest test_filename.py或nosetest test_filename.py,如果您运行python -m python -m unter test_fileName.py,则会获得2次失败。这是1次,1次失败,1个错误。

pytest与Test Failures (由于AssertionError)和Test errors (任何其他例外)(如unittest)。这不是一个错误,而是设计。

此线程中有一些讨论,以增加对这种类型的分离的支持,并导致了Pytest-Finer-FineDicts插件。

最新更新