Python, unittests, requests and timeouts
Want to test timeout handling of your code?
#!/usr/bin/python
# vim: set fileencoding=utf-8 shiftwidth=4 tabstop=4 expandtab textwidth=78:
import requests
if __name__ == '__main__':
exit( main() )
# test by running 'python3 -m unittest test.py'
import unittest
import unittest.mock as mock
class Test(unittest.TestCase):
def test_one( self ):
self.assertFalse( False )
@mock.patch( 'requests.get', side_effect=requests.exceptions.Timeout() )
def test_timeout( self, mock_get ):
with self.assertRaises( requests.exceptions.Timeout ):
mock_get()
self.assertTrue( True )