I believe your problem is that you're not patching in the right namespace. See where_to_patch documentation for unittest.mock.patch
.
Essentially, you're patching the definition of get_feed()
in mrss.feed_burner
but your view handler feed()
already has a reference to the original mrss.feed_burner.get_feed()
. To solve this problem, you need to patch the reference in your view file.
Based on your usage of get_feed
in your view function, I assume you're importing get_feed
like so
view_file.py
from mrss.feed_burner import get_feed
If so, you should be patching view_file.get_feed
like so:
def test_feed(self):
with patch('view_file.get_feed', new=lambda: '<xml></xml>'):
...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…