I have written a code in views.py
def fun():
try:
--Do some operation--
except OSError:
--Do something else--
And I have written a test case to cover total functionality of the code. To test the "except" part I have written the following code where it will raise "OSError",
with pytest.raises(OSError):
response = client.post(reverse('my_views_funurl'), follow=True)
But, I am getting this error
response = client.post(reverse('my_views_funurl'), follow=True)
E Failed: DID NOT RAISE
How to raise "OSError" to cover the except part in test cases. By the way I am using django-framework