From 82b3b1650857e6dd8bfbd708ca1f4690654cef71 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Thu, 12 Jul 2018 14:28:26 -0700 Subject: [PATCH 1/3] Rename deprecated @pytest.yield_fixture to @pytest.fixture --- tests/conftest.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8c279632..7cbfb439 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,7 +9,6 @@ import time import json import os - import requests import pytest import py @@ -108,14 +107,14 @@ def start_consul_instance(acl_master_token=None): return p, ports['http'] -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def consul_instance(): p, port = start_consul_instance() yield port p.terminate() -@pytest.yield_fixture +@pytest.fixture def consul_port(consul_instance): yield consul_instance # remove all data from the instance, to have a clean start @@ -123,7 +122,7 @@ def consul_port(consul_instance): requests.delete(base_uri + 'kv/?recurse=1') -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def acl_consul_instance(): acl_master_token = uuid.uuid4().hex p, port = start_consul_instance(acl_master_token=acl_master_token) @@ -131,7 +130,7 @@ def acl_consul_instance(): p.terminate() -@pytest.yield_fixture +@pytest.fixture def acl_consul(acl_consul_instance): ACLConsul = collections.namedtuple('ACLConsul', ['port', 'token']) port, token = acl_consul_instance From 021cf24ea76283368dae5961805b013035575d28 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Thu, 12 Jul 2018 14:29:34 -0700 Subject: [PATCH 2/3] Use /dev/null file instead of subprocess.PIPE This prevents hanging of whole testsuite --- tests/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7cbfb439..375f2362 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,8 +77,9 @@ def start_consul_instance(acl_master_token=None): command = command.format(bin=bin).strip() command = shlex.split(command) - p = subprocess.Popen( - command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + with open('/dev/null', 'w') as devnull: + p = subprocess.Popen( + command, stdout=devnull, stderr=devnull) # wait for consul instance to bootstrap base_uri = 'http://127.0.0.1:%s/v1/' % ports['http'] From 271f5457f876b73ead698dd7e681f712271c86e1 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Thu, 12 Jul 2018 14:31:23 -0700 Subject: [PATCH 3/3] Improved cleaning of consul after each test --- tests/conftest.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 375f2362..bb77449b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -108,6 +108,15 @@ def start_consul_instance(acl_master_token=None): return p, ports['http'] +def clean_consul(port): + # remove all data from the instance, to have a clean start + base_uri = 'http://127.0.0.1:%s/v1/' % port + requests.delete(base_uri + 'kv/', params={'recurse': 1}) + services = requests.get(base_uri + 'agent/services').json().keys() + for s in services: + requests.put(base_uri + 'agent/service/deregister/%s' % s) + + @pytest.fixture(scope="module") def consul_instance(): p, port = start_consul_instance() @@ -117,10 +126,9 @@ def consul_instance(): @pytest.fixture def consul_port(consul_instance): - yield consul_instance - # remove all data from the instance, to have a clean start - base_uri = 'http://127.0.0.1:%s/v1/' % consul_instance - requests.delete(base_uri + 'kv/?recurse=1') + port = consul_instance + yield port + clean_consul(port) @pytest.fixture(scope="module") @@ -136,6 +144,4 @@ def acl_consul(acl_consul_instance): ACLConsul = collections.namedtuple('ACLConsul', ['port', 'token']) port, token = acl_consul_instance yield ACLConsul(port, token) - # remove all data from the instance, to have a clean start - base_uri = 'http://127.0.0.1:%s/v1/' % port - requests.delete(base_uri + 'kv/?recurse=1') + clean_consul(port)