Skip to content

Commit

Permalink
Add offline mode to skip tests that require an internet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Luflosi committed Oct 1, 2021
1 parent aa702cb commit 92c9510
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
markers =
online: marks tests as requiring an internet connection
16 changes: 16 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--offline", action="store_true", help="Run tests in offline mode"
)

@pytest.fixture
def offline(request):
return request.config.getoption("--offline")

@pytest.fixture(autouse=True)
def skip_if_offline(request, offline):
if offline and request.node.get_closest_marker('online'):
pytest.skip('requires internet connection')
4 changes: 3 additions & 1 deletion test/test_capture_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# must be imported before 'requests'
from warcio.capture_http import capture_http
from pytest import raises
from pytest import raises, mark
import requests

import json
Expand Down Expand Up @@ -147,6 +147,7 @@ def nop_filter(request, response, recorder):
data = request.content_stream().read().decode('utf-8')
assert data == 'somedatatopost'

@mark.online()
def test_post_chunked(self):
warc_writer = BufferWARCWriter(gzip=False)

Expand Down Expand Up @@ -268,6 +269,7 @@ def test_warc_1_1(self):

os.remove(full_path)

@mark.online()
def test_remote(self):
with capture_http(warc_version='1.1', gzip=True) as writer:
requests.get('http://example.com/')
Expand Down
5 changes: 4 additions & 1 deletion test/test_capture_http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
from warcio.archiveiterator import ArchiveIterator

from pytest import raises
from pytest import raises, mark


# ==================================================================
Expand Down Expand Up @@ -44,6 +44,7 @@ def run():
thread.start()
time.sleep(0.1)

@mark.online()
def test_capture_http_proxy(self):
with capture_http() as warc_writer:
res = requests.get("http://example.com/test", proxies=self.proxies, verify=False)
Expand All @@ -63,6 +64,7 @@ def test_capture_http_proxy(self):
with raises(StopIteration):
assert next(ai)

@mark.online()
def test_capture_https_proxy(self):
with capture_http() as warc_writer:
res = requests.get("https://example.com/test", proxies=self.proxies, verify=False)
Expand Down Expand Up @@ -109,6 +111,7 @@ def test_capture_https_proxy(self):
with raises(StopIteration):
assert next(ai)

@mark.online()
def test_capture_https_proxy_same_session(self):
sesh = requests.session()
with capture_http() as warc_writer:
Expand Down

0 comments on commit 92c9510

Please sign in to comment.