不self.assertRaises覆蓋異常聲明這是我的函數:在python單元測試用例
def get_value(request, param):
s = get_string(request, param)
value = re.search('(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)', s)
if not value:
print 'match not found!'
raise Exception('incorrect format: %s' % param)
測試功能:
def test_get_value(self):
m = test_mocks.HttpRequestMock(REQUEST = {'start_date': '2011.07.31'})
print '*************************'
print 'date format changed'
self.assertRaises(Exception, get_value, (m, 'start_date'))
print '*********************
get_value
不打印:比賽未找到!
感謝Bren的編輯。 –
你的'helpers.get_date_param'調用'get_value'? – Ian
更改了通話...我修改了發佈此問題的功能名稱! –