0

I have a class like this (simplified):

class DataGainer:
    def __init__(self):
        self.last_url = None
    
    def get_data(self, url):
        response = requests.get(url) # very long request
        self.last_url = response.url
        ...

As a test I'd like to make sure, that after the request I have correct url in the last_url property. So I do not care, what data will be returned by get, but I need to have Response object with url. That is why I can't use mock. Maybe there is a way to pass timeout argument somehow?

My test so far looks this way (simplified):

def test_last_url():
    url = 'some.url'
    dg = DataGainer()
    dg.get_data(url)
    assert dg.last_url == url

This test is very slow, because of the get request. How can I make it faster?

P.s.: I'd like to check last_url because I process it somehow

Ivan Mishalkin
  • 1,049
  • 9
  • 25
  • Do the answers to this [question](https://stackoverflow.com/questions/15753390/how-can-i-mock-requests-and-the-response) help at all? – quamrana Apr 29 '22 at 17:18
  • Unfortunately, all the answers offer mocking the response without actual sending the request. The responses library gives an opportunity to pass the request through, but I can't modify it to set timeout of 1ms, for example – Ivan Mishalkin May 02 '22 at 11:23

0 Answers0