Trying to get new client when port is already in use.

This commit is contained in:
Roland 2023-09-13 10:38:42 -06:00
parent 459de4de32
commit dae780e02f
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93

View file

@ -135,9 +135,19 @@ def test_client() -> ReusableClient:
api_app.blueprint(bp)
ROUTES_ATTACHED = True
client = ReusableClient(api_app)
with client:
yield client
for _ in range(5):
# Sometimes the Sanic client tries to use a port already in use, try again...
try:
client = ReusableClient(api_app)
with client:
yield client
break
except OSError as e:
# Ignore errors where the port was already in use.
if 'address already in use' not in str(e):
raise
else:
raise RuntimeError('Test never got unused port')
@pytest.fixture()