मैं अपवाद के लिए परीक्षण करने की कोशिश कर रहा हूं।assertRaises के साथ यूनिट टेस्ट समस्या
मेरे पास है:
def test_set_catch_status_exception(self):
mro = self.mro
NEW_STATUS = 'No such status'
self.assertRaises(ValueError,mro.setStatus(NEW_STATUS))
मैं निम्नलिखित त्रुटि मिलती है:
======================================================================
ERROR: test_set_catch_status_exception (__main__.TestManagementReviewGoalGetters)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_ManagementReviewObjective.py", line 68, in test_set_catch_status_exception
self.assertRaises(ValueError,mro.setStatus(NEW_STATUS))
File "/Users/eric/Dropbox/ManagementReview.py", line 277, in setStatus
raise ValueError('%s is not in the list of allowed statuses: %s' % (status,LIST_OF_STATUSES))
ValueError: No such status is not in the list of allowed statuses: ['Concern or Delay', 'On Track', 'Off Track/Needs Attention']
----------------------------------------------------------------------
धन्यवाद
कि यह किया! धन्यवाद। :) –
@Eric: कोई समस्या नहीं। – unutbu
मैं पिचर्म आईडीई में पायथन 3.3 दुभाषिया का उपयोग कर रहा हूं। क्या होगा यदि मैं परीक्षण के तहत फ़ंक्शन में तर्क पारित करना चाहता हूं और वांछित त्रुटि नहीं उठाई गई स्थिति में एक संदेश भी शामिल करना है? उदाहरण - 'self.assertRaises (ValueError, person.set_age_method, -10, "त्रुटि: व्यक्ति की उम्र नकारात्मक नहीं हो सकती है।") इसके साथ, मुझे अपवाद मिलता है:' set_age_method 2 स्थितित्मक तर्क लेता है लेकिन 3 दिया गया था। मैं यह कैसे तय करुं ? बीटीडब्ल्यू, इस दावे के लिए दस्तावेज़ स्पष्ट रूप से आपको यह नहीं बताते हैं कि यह कैसे करें। https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaises। ** kwds क्या है? – testerjoe2