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 1 commit
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
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
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minversion = 2.5.0

[testenv]
extras = testing
commands = coverage run -m pytest {posargs}
commands = coverage run -m pytest -W error {posargs}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to add this to pytest.ini instead:

[pytest]
filterwarnings = error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, there is some config in setup.cfg already, I've moved it there.


[testenv:coverage-report]
deps = coverage
Expand Down