Skip to content

Commit

Permalink
Merge pull request #13 from BeyondEvil/lazy-load-requests
Browse files Browse the repository at this point in the history
Lazy load requests dependency
  • Loading branch information
BeyondEvil authored May 23, 2020
2 parents 9463d0a + a24a646 commit 32ed5aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
-------------

**1.4.2 (unreleased)**

* Lazy load requests dependency to reduce cost

* Thanks to `@boxed <https://github.com/boxed>`_ for the PR

**1.4.1 (2017-06-22)**

* Update dependency of requests to require v2.9 or later.
Expand Down
9 changes: 6 additions & 3 deletions pytest_base_url/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import os

import pytest
import requests
from requests.packages.urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter


@pytest.fixture(scope="session")
Expand All @@ -22,8 +19,14 @@ def base_url(request):
@pytest.fixture(scope="session", autouse=True)
def _verify_url(request, base_url):
"""Verifies the base URL"""

verify = request.config.option.verify_base_url
if base_url and verify:
# Lazy load requests to reduce cost for tests that don't use the plugin
import requests
from requests.packages.urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter

session = requests.Session()
retries = Retry(backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
session.mount(base_url, HTTPAdapter(max_retries=retries))
Expand Down

0 comments on commit 32ed5aa

Please sign in to comment.