Python py.test将索引器错误/键错误报告为失败而不是错误
使用py.test运行上述代码,它会将test\u error测试方法报告为测试失败,而不是测试错误。使用unittest运行它会将test_错误显示为错误而不是失败,您对此有何想法Python py.test将索引器错误/键错误报告为失败而不是错误,python,python-3.x,pytest,python-unittest,Python,Python 3.x,Pytest,Python Unittest,使用py.test运行上述代码,它会将test\u error测试方法报告为测试失败,而不是测试错误。使用unittest运行它会将test_错误显示为错误而不是失败,您对此有何想法 Update:同样的代码,NoSE也将它视为一个错误而不是TestIOLT失败,这是Py.Test.\中的一个问题吗?p> 更新:如果你不确定我指的是什么,如果你运行py.test test\u filename.py,你会得到1次通过,2次失败,如果你运行python-m unittest test\u file
Update:同样的代码,NoSE也将它视为一个错误而不是TestIOLT失败,这是Py.Test.\中的一个问题吗?p>
更新:如果你不确定我指的是什么,如果你运行py.test test\u filename.py,你会得到1次通过,2次失败,如果你运行python-m unittest test\u filename.py或nosetest test\u filename.py,它是1次通过,1次失败,1次错误。pytest没有区分测试失败(由于
断言错误)和测试错误(任何其他例外)如unittest
一样。这不是一个bug,而是出于设计
在中进行了一些讨论,以添加对这种类型的分离的支持,这导致了插件。用代码行打印代码不是很方便……您能澄清您的问题吗py。test
将测试方法引发的任何异常视为失败。另一方面,错误适用于夹具设置/tea时的情况罗德敦的结局并不好。
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()