Skip to content

Fix: Avoid warning on latest Pytest versions #97

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,29 @@ def event_loop(request):
loop.close()


@pytest.fixture
def unused_tcp_port():
def _unused_tcp_port():
"""Find an unused localhost TCP port from 1024-65535 and return it."""
with contextlib.closing(socket.socket()) as sock:
sock.bind(('127.0.0.1', 0))
return sock.getsockname()[1]


@pytest.fixture
def unused_tcp_port():
return _unused_tcp_port()


@pytest.fixture
def unused_tcp_port_factory():
"""A factory function, producing different unused TCP ports."""
produced = set()

def factory():
"""Return an unused port."""
port = unused_tcp_port()
port = _unused_tcp_port()

while port in produced:
port = unused_tcp_port()
port = _unused_tcp_port()

produced.add(port)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ show_missing = true
[tool:pytest]
addopts = -rsx --tb=short
testpaths = tests
filterwarnings = error

[metadata]
# ensure LICENSE is included in wheel metadata
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def mock_unused_tcp_port():
else:
return 10000 + counter

monkeypatch.setattr(pytest_asyncio.plugin, 'unused_tcp_port',
monkeypatch.setattr(pytest_asyncio.plugin, '_unused_tcp_port',
mock_unused_tcp_port)

assert unused_tcp_port_factory() == 10000
Expand Down