Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offline mode to skip tests that require an internet connection #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


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

def pytest_configure(config):
config.addinivalue_line(
"markers", "online: marks tests as requiring an internet connection"
)

@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