title: Using pytest to test a function that uses request library
body: <p>I have a python function that calls out to an API using the request function. I want to test a 200 path, and then test a 500 error. I can't seem to figure out how to do it when looking at the requests-mock documentation.</p>
  
  <p>Here is what I want to test.</p>
  
  <pre><code>def get_sku_data(sku: str):
      """
      Retrieve a single product from api
      """
      uri = app.config["SKU_URI"]
      url = f"{uri}/{sku}"
      headers = {
          "content-type": "application/json",
          "cache-control": "no-cache",
          "accept": "application/json",
      }
      try:
          retry_times = 3
          response = retry_session(retries=retry_times).get(url, headers=headers)
          return response.json()
      except ConnectionError as ex:
          raise Exception(f"Could not connect to sku api at {uri}. {ex}.")
      except requests.exceptions.RetryError:
          raise Exception(f"Attempted to connect to {uri} {retry_times} times.")
  
  def retry_session(
      retries, backoff_factor=0.3, status_forcelist=(500, 502, 503, 504)
  ) -&gt; requests.Session:
      """
      Performs a retry
      """
      session = requests.Session()
      retry = Retry(
          total=retries,
          read=retries,
          connect=retries,
          backoff_factor=backoff_factor,
          status_forcelist=status_forcelist,
      )
      adapter = HTTPAdapter(max_retries=retry)
      session.mount("http://", adapter)
      session.mount("https://", adapter)
      return session
  </code></pre>
  
  <p>Here is my test stub that I'm trying to get going</p>
  
  <pre><code># These test use pytest https://pytest.readthedocs.io/en/latest/
  
  # Note: client is a pytest fixture that is dependency injected from src/tests/conftest.py
  
  import json
  import pytest
  from src.app import create_app
  import requests
  import requests_mock
  
  
  @pytest.fixture
  def app():
      app = create_app()
      return app
  
  
  def test():
      session = requests.Session()
      adapter = requests_mock.Adapter()
      session.mount("mock", adapter)
      adapter.register_uri("GET", "mock://12", text="data")
      resp = session.get("mock://12")
      assert resp.status_code == 200
      assert resp.text == "data"
  </code></pre>
  
  <p>I'm a bit new to python testing, so any help would be very much appreciated. </p>