From ecb543142d9ae4e26e691fa89f702c205ef318ee Mon Sep 17 00:00:00 2001 From: Andreas Maier Date: Sat, 11 Nov 2023 19:19:03 +0100 Subject: [PATCH] Added env var TESTLOG to enable logging for end2end tests Signed-off-by: Andreas Maier --- Makefile | 1 + docs/changes.rst | 3 +++ docs/development.rst | 8 +++++--- tests/end2end/test_session.py | 11 +++++++---- tests/end2end/utils.py | 11 +++++++++++ 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f6df0069..755ef88b 100644 --- a/Makefile +++ b/Makefile @@ -240,6 +240,7 @@ help: @echo " random - one random choice from the complete list of resources (default)" @echo " all - the complete list of resources" @echo " - the resources with names matching the regexp pattern" + @echo " TESTLOG=1 - Enable logging for end2end tests" @echo " PACKAGE_LEVEL - Package level to be used for installing dependent Python" @echo " packages in 'install' and 'develop' targets:" @echo " latest - Latest package versions available on Pypi" diff --git a/docs/changes.rst b/docs/changes.rst index 6d055dcd..1619fbec 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -59,6 +59,9 @@ Released: not yet * Increased minimum zhmcclient version to 1.12.0 to pick up fixes and functionality. (issue #510) +* Tests: Added an environment variable TESTLOG to enable logging for end2end + tests. (issue #414) + **Cleanup:** **Known issues:** diff --git a/docs/development.rst b/docs/development.rst index dfffeea1..89cb56ea 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -108,7 +108,6 @@ There are two kinds of tests: * end2end tests: End2end testcases run against an HMC or set of HMCs defined in an HMC inventory file, with credentials from an HMC vault file. - Running function tests ^^^^^^^^^^^^^^^^^^^^^^ @@ -137,6 +136,8 @@ The positional arguments of the ``tox`` command are passed to ``py.test`` using its ``-k`` option. Invoke ``py.test --help`` for details on the expression syntax of its ``-k`` option. +In addition to ``TESTCASES``, the environment variable ``TESTOPTS`` can be +specified for function tests. Invoke ``make help`` for details. Running end2end tests ^^^^^^^^^^^^^^^^^^^^^ @@ -199,8 +200,9 @@ Examples: $ TESTINVENTORY=./hmc_inventory.yaml TESTVAULT=./hmc_vault.yaml make end2end -In addition, the variables ``TESTCASES`` and ``TESTOPTS`` can be specified, -as for function tests. Invoke ``make help`` for details. +In addition to ``TESTHMC``, ``TESTINVENTORY`` and ``TESTVAULT``, the environment +variables ``TESTCASES``, ``TESTOPTS``, ``TESTRESOURCES`` and ``TESTLOG`` can be +specified for end2end tests. Invoke ``make help`` for details. .. _HMC inventory file: https://python-zhmcclient.readthedocs.io/en/latest/development.html#hmc-inventory-file .. _HMC vault file: https://python-zhmcclient.readthedocs.io/en/latest/development.html#hmc-vault-file diff --git a/tests/end2end/test_session.py b/tests/end2end/test_session.py index cd068b41..7f0b6345 100644 --- a/tests/end2end/test_session.py +++ b/tests/end2end/test_session.py @@ -29,10 +29,13 @@ # pylint: enable=line-too-long,unused-import from .utils import run_zhmc, create_hmc_session, delete_hmc_session, \ - is_valid_hmc_session + is_valid_hmc_session, env2bool urllib3.disable_warnings() +# Enable logging via environment +TESTLOG = env2bool('TESTLOG') + def assert_session_create( rc, stdout, stderr, hmc_definition, # noqa: F811 @@ -528,7 +531,7 @@ def test_session_create( logon_args = prepare_logon_args(logon_opts, hmc_definition) pdb_ = run == 'pdb' - log = run == 'log' + log = (run == 'log' or TESTLOG) zhmc_args = logon_args + ['session', 'create'] @@ -777,7 +780,7 @@ def test_session_delete( logon_args = prepare_logon_args(logon_opts, hmc_definition) pdb_ = run == 'pdb' - log = run == 'log' + log = (run == 'log' or TESTLOG) zhmc_args = logon_args + ['session', 'delete'] @@ -1032,7 +1035,7 @@ def test_session_command( logon_args = prepare_logon_args(logon_opts, hmc_definition) pdb_ = run == 'pdb' - log = run == 'log' + log = (run == 'log' or TESTLOG) zhmc_args = logon_args + ['cpc', 'list', '--names-only'] diff --git a/tests/end2end/utils.py b/tests/end2end/utils.py index 2e60a251..ead38475 100644 --- a/tests/end2end/utils.py +++ b/tests/end2end/utils.py @@ -30,6 +30,17 @@ TEST_PREFIX = 'zhmcclient_tests_end2end' +def env2bool(name): + """ + Evaluate the (string) value of the specified environment variable as a + boolean value and return the result as a bool. + + The following variable values are considered True: 'true', 'yes', '1'. + Any other value or if the variable is not set, is considered False. + """ + return os.getenv(name, 'false').lower() in ('true', 'yes', '1') + + class End2endTestWarning(UserWarning): """ Python warning indicating an issue with an end2end test.