मैं एक यूनिट परीक्षण लिखने की कोशिश कर रहा हूं जो सुनिश्चित करेगा कि आवश्यक होने पर HTTPException उठाया जाएगा।assertRises विफलता
import unittest
from requests import HTTPError
import pyport
# Code omitted...
def test_bad_item_type(self):
"""A bad item type should raise a HTTPError"""
test_type = 'bad'
test_id = 1986134
self.assertRaises(HTTPError, pyport.get_item(test_type, test_id))
निम्नलिखित में से कौन पैदा करता है:: यहाँ परीक्षा है
ERROR: test_bad_item_type (__main__.TestPyportFunctions) A bad item
type should raise requests.HTTPError
----------------------------------------------------------------------
Traceback (most recent call last): File "./tests.py", line 65, in
test_bad_item_type
self.assertRaises(HTTPError, pyport.get_item(test_type, test_id)) File "/home/sean/workspace/pyport/pyport.py", line 54, in get_item
response.raise_for_status() File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 741, fin raise_for_status
raise HTTPError('%s Client Error' % self.status_code) HTTPError: 404 Client Error
अपवाद उठाया है, लेकिन यह परीक्षण द्वारा पकड़ा नहीं है। यह this question में जो हुआ, उसके समान है, लेकिन यह काफी समान नहीं है। क्या कोई मुझे बता सकता है कि मैं क्या खो रहा हूं?
आपके विस्तृत स्पष्टीकरण के लिए धन्यवाद। –