Skip to content

Commit

Permalink
test: extract common function for reuse
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman committed Jun 18, 2023
1 parent 8f015e5 commit 25ea246
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
16 changes: 16 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Common test functions.
"""


def assert_socket_blocked(result, passed=0, skipped=0, failed=1):
"""
Uses built in methods to test for common failure scenarios.
Usually we only test for a single failure,
but sometimes we want to test for multiple conditions,
so we can pass in the expected counts.
"""
result.assert_outcomes(passed=passed, skipped=skipped, failed=failed)
result.stdout.fnmatch_lines(
"*Socket*Blocked*Error: A test tried to use socket.socket.*"
)
2 changes: 1 addition & 1 deletion tests/test_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from conftest import unix_sockets_only
from test_socket import assert_socket_blocked
from tests.common import assert_socket_blocked


@unix_sockets_only
Expand Down
11 changes: 1 addition & 10 deletions tests/test_precedence.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
"""Test module to express precedence tests between the different
configuration combinations"""


def assert_socket_blocked(result, passed=0, skipped=0, failed=1):
"""Uses built in methods to test for common failure scenarios.
Usually we only test for a single failure,
but sometimes we want to test for multiple conditions,
so we can pass in the expected counts."""
result.assert_outcomes(passed=passed, skipped=skipped, failed=failed)
result.stdout.fnmatch_lines(
"*Socket*Blocked*Error: A test tried to use socket.socket.*"
)
from tests.common import assert_socket_blocked


def test_disable_via_fixture(testdir):
Expand Down
8 changes: 1 addition & 7 deletions tests/test_socket.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from conftest import unix_sockets_only
from tests.common import assert_socket_blocked

PYFILE_SOCKET_USED_IN_TEST_ARGS = """
import socket
Expand All @@ -26,13 +27,6 @@ def test_socket():
"""


def assert_socket_blocked(result):
result.assert_outcomes(passed=0, skipped=0, failed=1)
result.stdout.fnmatch_lines(
"*SocketBlockedError: A test tried to use socket.socket.*"
)


@pytest.mark.parametrize(
"pyfile",
[
Expand Down

0 comments on commit 25ea246

Please sign in to comment.