Skip to content

Commit 2546fe4

Browse files
committed
Add offline mode to skip tests that require an internet connection
Closes #133.
1 parent aa702cb commit 2546fe4

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

test/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption(
6+
"--offline", action="store_true", help="Run tests in offline mode"
7+
)
8+
9+
def pytest_configure(config):
10+
config.addinivalue_line(
11+
"markers", "online: marks tests as requiring an internet connection"
12+
)
13+
14+
@pytest.fixture
15+
def offline(request):
16+
return request.config.getoption("--offline")
17+
18+
@pytest.fixture(autouse=True)
19+
def skip_if_offline(request, offline):
20+
if offline and request.node.get_closest_marker('online'):
21+
pytest.skip('requires internet connection')

test/test_capture_http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# must be imported before 'requests'
77
from warcio.capture_http import capture_http
8-
from pytest import raises
8+
from pytest import raises, mark
99
import requests
1010

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

150+
@mark.online()
150151
def test_post_chunked(self):
151152
warc_writer = BufferWARCWriter(gzip=False)
152153

@@ -268,6 +269,7 @@ def test_warc_1_1(self):
268269

269270
os.remove(full_path)
270271

272+
@mark.online()
271273
def test_remote(self):
272274
with capture_http(warc_version='1.1', gzip=True) as writer:
273275
requests.get('http://example.com/')

test/test_capture_http_proxy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import requests
88
from warcio.archiveiterator import ArchiveIterator
99

10-
from pytest import raises
10+
from pytest import raises, mark
1111

1212

1313
# ==================================================================
@@ -44,6 +44,7 @@ def run():
4444
thread.start()
4545
time.sleep(0.1)
4646

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

67+
@mark.online()
6668
def test_capture_https_proxy(self):
6769
with capture_http() as warc_writer:
6870
res = requests.get("https://example.com/test", proxies=self.proxies, verify=False)
@@ -109,6 +111,7 @@ def test_capture_https_proxy(self):
109111
with raises(StopIteration):
110112
assert next(ai)
111113

114+
@mark.online()
112115
def test_capture_https_proxy_same_session(self):
113116
sesh = requests.session()
114117
with capture_http() as warc_writer:

0 commit comments

Comments
 (0)