0
def different_type():
if types == 'int64':
pass
else:
raise KeyError('field type not recognized')
def test_TypeErrorHandling():
with pytest.raises(KeyError) as excinfo:
different_type()
assert excinfo.value.message == 'field type not recognized'
print excinfo.value.message
當前我有兩段代碼,並且嘗試打印出test_TypeErrorHandling()中定義的錯誤消息(字段類型未識別)在命令提示符屏幕上,當我做pytest運行。但它不會打印出來。嘗試在pytest屏幕上打印異常錯誤
任何意見呢?謝謝
您的代碼示例似乎不是自包含的。例如,變量'types'從哪裏來?是否有可能在最後幾行中縮進級別有點搞砸了? – aepsil0n