OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Mocking a http.get function isnt working in pytest

  • Thread starter Thread starter Sagar Ghanwat
  • Start date Start date
S

Sagar Ghanwat

Guest
The test file contains

Code:
from lib.sync_mdl_status import update_mdl_status
def test_status_updater_mdl(self):
    mock_mdl_http_get = patch('lib.sync_mdl_status.http.get').start()
    mock_mdl_http_get.return_value.status_code = 200

    batch = update_mdl_status(self.postgresql.url(), "test", 1, aws_auth_token)

The update_mdl_status has

Code:
http = requests.Session()
http.mount("http://", TimeoutHTTPAdapter(max_retries=HTTP_RETRY_STRATEGY))
http.mount("https://", TimeoutHTTPAdapter(max_retries=HTTP_RETRY_STRATEGY))
http.get(f"{mdl_endpoint}/{mdl_id}", headers=mdl_headers)

The mocking of http.get isnt working. Tried using patch and fixtures but it isnt working. An actual call is being made to the api instead of using mock response.
<p>The test file contains</p>
<pre><code>from lib.sync_mdl_status import update_mdl_status
def test_status_updater_mdl(self):
mock_mdl_http_get = patch('lib.sync_mdl_status.http.get').start()
mock_mdl_http_get.return_value.status_code = 200

batch = update_mdl_status(self.postgresql.url(), "test", 1, aws_auth_token)
</code></pre>
<p>The update_mdl_status has</p>
<pre><code>http = requests.Session()
http.mount("http://", TimeoutHTTPAdapter(max_retries=HTTP_RETRY_STRATEGY))
http.mount("https://", TimeoutHTTPAdapter(max_retries=HTTP_RETRY_STRATEGY))
http.get(f"{mdl_endpoint}/{mdl_id}", headers=mdl_headers)
</code></pre>
<p>The mocking of http.get isnt working. Tried using patch and fixtures but it isnt working. An actual call is being made to the api instead of using mock response.</p>
 

Latest posts

Online statistics

Members online
1
Guests online
6
Total visitors
7
Top