From 8ce3379ec5ec394ec3e0aac242a57c3428ce85d3 Mon Sep 17 00:00:00 2001 From: Mikhail Ushanov Date: Thu, 12 May 2016 18:18:40 +0300 Subject: [PATCH] Added logging to functional tests Signed-off-by: Mikhail Ushanov --- tests/functional/__init__.py | 22 +++++++++++++++++++++- tests/functional/test_volumes.py | 5 +++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py index 9269b7c..b928f87 100644 --- a/tests/functional/__init__.py +++ b/tests/functional/__init__.py @@ -34,7 +34,7 @@ def client(request): os.getenv("scaleio_host"), os.getenv("scaleio_user"), os.getenv("scaleio_passwd"), - os.getenv("scaleio_is_secure") + bool(int(os.getenv("scaleio_is_secure"))) ) pyscaleio.add_client(client) request.addfinalizer(ScaleIOClientsManager().deregister) @@ -74,3 +74,23 @@ def setup_teardown(request): cleanup_pools() request.addfinalizer(cleanup_volumes) request.addfinalizer(cleanup_pools) + + +@pytest.fixture +def setup_logging(request): + """Fixture that setups debug logging.""" + + import logging + + logger = logging.getLogger("pyscaleio") + logger.setLevel(logging.DEBUG) + + formatter = logging.Formatter( + "%(asctime)s.%(msecs)03d %(levelname)s: %(message)s", + "%Y.%m.%d %H:%M:%S") + + handler = logging.StreamHandler() + handler.setFormatter(formatter) + logger.addHandler(handler) + + request.addfinalizer(lambda: logger.removeHandler(handler)) diff --git a/tests/functional/test_volumes.py b/tests/functional/test_volumes.py index 4de20c1..70a2a1c 100644 --- a/tests/functional/test_volumes.py +++ b/tests/functional/test_volumes.py @@ -7,9 +7,10 @@ from pyscaleio import constants from . import _get_test_name -from . import client, setup_teardown +from . import client, setup_teardown, setup_logging assert client assert setup_teardown +assert setup_logging @pytest.fixture @@ -27,7 +28,7 @@ def test_get_system(): assert len(System.all()) == 1 -def test_create_volume(storage_pool): +def test_create_volume(storage_pool, setup_logging): volume = Volume.create(4, storage_pool["id"], name=_get_test_name(1))