Skip to content

Commit ade2121

Browse files
committed
Fix: Avoid warning on latest Pytest versions
Pytest added a deprecation warning to signal fixtures being called directly as functions. Ref: pytest-dev/pytest#3661 Ref: https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly
1 parent 1ada096 commit ade2121

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pytest_asyncio/plugin.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,29 @@ def event_loop(request):
174174
loop.close()
175175

176176

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

184183

184+
@pytest.fixture
185+
def unused_tcp_port():
186+
return _unused_tcp_port()
187+
188+
185189
@pytest.fixture
186190
def unused_tcp_port_factory():
187191
"""A factory function, producing different unused TCP ports."""
188192
produced = set()
189193

190194
def factory():
191195
"""Return an unused port."""
192-
port = unused_tcp_port()
196+
port = _unused_tcp_port()
193197

194198
while port in produced:
195-
port = unused_tcp_port()
199+
port = _unused_tcp_port()
196200

197201
produced.add(port)
198202

tests/test_simple.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def mock_unused_tcp_port():
104104
else:
105105
return 10000 + counter
106106

107-
monkeypatch.setattr(pytest_asyncio.plugin, 'unused_tcp_port',
107+
monkeypatch.setattr(pytest_asyncio.plugin, '_unused_tcp_port',
108108
mock_unused_tcp_port)
109109

110110
assert unused_tcp_port_factory() == 10000

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ minversion = 2.5.0
44

55
[testenv]
66
extras = testing
7-
commands = coverage run -m pytest {posargs}
7+
commands = coverage run -m pytest -W error {posargs}
88

99
[testenv:coverage-report]
1010
deps = coverage

0 commit comments

Comments
 (0)