From 75212cda3f45f1e78c1fe582e04da4b619e0c668 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 16 Mar 2016 16:34:16 +0100 Subject: [PATCH] Improve tests on Travis --- tests/conftest.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 59eca77b..17add21f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -81,16 +81,25 @@ def _get_unused_port(): def server(request, loop, port_manager, monkeypatch): """A GNS3 server""" - port = _get_unused_port() - host = "localhost" app = web.Application() for method, route, handler in Route.get_routes(): app.router.add_route(method, route, handler) for module in MODULES: instance = module.instance() instance.port_manager = port_manager - srv = loop.create_server(app.make_handler(), host, port) - srv = loop.run_until_complete(srv) + + host = "localhost" + + # We try multiple time. Because on Travis test can fail when because the port is taken by someone else + for i in range(0, 5): + port = _get_unused_port() + try: + srv = loop.create_server(app.make_handler(), host, port) + srv = loop.run_until_complete(srv) + except OSError: + pass + else: + break def tear_down(): for module in MODULES: