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

Fix pytest-socket raises IndexError with httpx #85

Merged
merged 1 commit into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.6"
python = "^3.6.2"
pytest = ">=3.6.3"

[tool.poetry.dev-dependencies]
Expand All @@ -42,6 +42,7 @@ pytest-flake8 = "^1.0.4"
asynctest = "^0.13.0"
requests = "^2.26.0"
starlette = "^0.14.2"
httpx = "^0.21.1"

[tool.poetry.plugins.pytest11]
socket = 'pytest_socket'
Expand Down
2 changes: 1 addition & 1 deletion pytest_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class GuardedSocket(socket.socket):
def __new__(cls, *args, **kwargs):
try:
is_unix_socket = args[0] == socket.AF_UNIX
except AttributeError:
except (AttributeError, IndexError):
# AF_UNIX not supported on Windows https://bugs.python.org/issue33408
is_unix_socket = False

Expand Down
21 changes: 20 additions & 1 deletion tests/test_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import socket

import pytest

from test_socket import assert_socket_blocked

unix_sockets_only = pytest.mark.skipif(
not hasattr(socket, "AF_UNIX"),
Expand Down Expand Up @@ -54,3 +54,22 @@ def test_app():
""")
result = testdir.runpytest("--verbose", "--disable-socket", "--allow-unix-socket")
result.assert_outcomes(passed=1, skipped=0, failed=0)


@unix_sockets_only
def test_httpx_fails(testdir):
testdir.makepyfile("""
import pytest
import httpx


@pytest.fixture(autouse=True)
def anyio_backend():
return "asyncio"

async def test_httpx():
async with httpx.AsyncClient() as client:
await client.get("http://www.example.com/")
""")
result = testdir.runpytest("--verbose", "--disable-socket", "--allow-unix-socket")
assert_socket_blocked(result)