Skip to content

Commit

Permalink
Add a network pytest mark for tests that use the network
Browse files Browse the repository at this point in the history
  • Loading branch information
mcepl committed Dec 19, 2023
1 parent 377d931 commit aa5ca6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ testpaths = [
]
markers = [
# mark a test to allow socket usage
"requests"
"requests",
"network: test case requires network connection",
]
4 changes: 4 additions & 0 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_no_records(self, tmpdir):
result = c.get("http://tests.python-zeep.org/example.wsdl")
assert result is None

@pytest.mark.network
def test_has_expired(self, tmpdir):
c = cache.SqliteCache(path=tmpdir.join("sqlite.cache.db").strpath)
c.add("http://tests.python-zeep.org/example.wsdl", b"content")
Expand All @@ -51,6 +52,7 @@ def test_has_not_expired(self, tmpdir):
assert result == b"content"


@pytest.mark.network
def test_memory_cache_timeout(tmpdir):
c = cache.InMemoryCache()
c.add("http://tests.python-zeep.org/example.wsdl", b"content")
Expand All @@ -76,13 +78,15 @@ class TestIsExpired:
def test_timeout_none(self):
assert cache._is_expired(100, None) is False

@pytest.mark.network
def test_has_expired(self):
timeout = 7200
utcnow = datetime.datetime.utcnow()
value = utcnow + datetime.timedelta(seconds=timeout)
with freezegun.freeze_time(utcnow):
assert cache._is_expired(value, timeout) is False

@pytest.mark.network
def test_has_not_expired(self):
timeout = 7200
utcnow = datetime.datetime.utcnow()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_wsse_username.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test_password_text():
assert_nodes_equal(envelope, expected)


@pytest.mark.network
@freeze_time("2016-05-08 12:00:00")
def test_password_digest(monkeypatch):
monkeypatch.setattr(os, "urandom", lambda x: b"mocked-random")
Expand Down Expand Up @@ -138,6 +139,7 @@ def test_password_digest(monkeypatch):
assert_nodes_equal(envelope, expected)


@pytest.mark.network
@freeze_time("2016-05-08 12:00:00")
def test_password_digest_custom(monkeypatch):
monkeypatch.setattr(os, "urandom", lambda x: b"mocked-random")
Expand Down Expand Up @@ -323,6 +325,7 @@ def test_timestamp_token():
assert_nodes_equal(envelope, expected)


@pytest.mark.network
@freeze_time("2016-05-08 12:00:00")
def test_bytes_like_password_digest(monkeypatch):
monkeypatch.setattr(os, "urandom", lambda x: b"mocked-random")
Expand Down

0 comments on commit aa5ca6e

Please sign in to comment.