Skip to content

Commit 923fe9a

Browse files
authored
Merge pull request #97 from JoseKilo/fix/pytest-warning-calling-fixture-as-function
Fix: Avoid warning on latest Pytest versions
2 parents 1ada096 + 7087f57 commit 923fe9a

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
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

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ show_missing = true
77
[tool:pytest]
88
addopts = -rsx --tb=short
99
testpaths = tests
10+
filterwarnings = error
1011

1112
[metadata]
1213
# ensure LICENSE is included in wheel metadata

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

0 commit comments

Comments
 (0)