Skip to content

Commit

Permalink
test: refactor outcomes to helper assertion
Browse files Browse the repository at this point in the history
Since each time we're asserting the output of the test as well as the
test outcome, we can clarify the fields of `parse_outcomes` in one
place.

Signed-off-by: Mike Fiedler <[email protected]>
  • Loading branch information
miketheman committed May 29, 2020
1 parent 7bc7e87 commit 840691a
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions tests/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def reenable_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.*
""")
Expand Down Expand Up @@ -48,14 +49,12 @@ def test_socket():
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
""")
result = testdir.runpytest("--verbose")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


def test_global_disable_via_cli_flag(testdir):
testdir.makepyfile(PYFILE_SOCKET_USED_IN_TEST)
result = testdir.runpytest("--verbose", "--disable-socket")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


Expand All @@ -76,7 +75,6 @@ def test_global_disable_via_config(testdir):
addopts = --disable-socket
""")
result = testdir.runpytest("--verbose")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


Expand All @@ -90,7 +88,6 @@ def test_socket():
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
""")
result = testdir.runpytest("--verbose")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


Expand All @@ -104,7 +101,6 @@ def test_socket():
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
""")
result = testdir.runpytest("--verbose", "--disable-socket")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


Expand Down Expand Up @@ -136,7 +132,6 @@ def test_disable_socket_urllib():
assert urlopen('http:https://httpbin.org/get').getcode() == 200
""")
result = testdir.runpytest("--verbose", "--disable-socket")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


Expand All @@ -153,7 +148,6 @@ def test_disable_socket_urllib():
assert urlopen('http:https://httpbin.org/get').getcode() == 200
""")
result = testdir.runpytest("--verbose")
result.assert_outcomes(0, 0, 1)
assert_socket_blocked(result)


Expand Down

0 comments on commit 840691a

Please sign in to comment.