From 89bc267d984baf6c3a5c0966c58d5390d099a8a1 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Campos Date: Tue, 26 May 2020 11:51:23 -0300 Subject: [PATCH 1/2] Fix all tests entry point Running test_playbook_runs.py would result of running only the last collected test but showing the name of the other tests instead. To fix that the test_path was moved to an argument set by a method decorator. --- tests/test_playbook_runs.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/test_playbook_runs.py b/tests/test_playbook_runs.py index 4c63fe72..e44f4785 100644 --- a/tests/test_playbook_runs.py +++ b/tests/test_playbook_runs.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +import functools import tempfile from subprocess import Popen @@ -59,11 +60,16 @@ def get_test_groups(): return groups -def rename(newname): - def decorator(f): - f.__name__ = newname - return f +def prepare_test(test_name, test_path): + def decorator(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + kwargs["test_path"] = test_path + return func(*args, **kwargs) + return wrapper + + decorator.__name__ = test_name return decorator @@ -73,14 +79,15 @@ for group_name, group_tests in get_test_groups().items(): _tests = {} for test_config in group_tests: test_name = test_config["name"].replace("-", "_") + test_path = test_config["path"] @pytest.mark.skipif( os.getenv("IPA_SERVER_HOST") is None, reason="Environment variable IPA_SERVER_HOST must be set", ) - @rename(test_name) - def method(self): - result = run_playbook(test_config["path"]) + @prepare_test(test_name, test_path) + def method(self, test_path): + result = run_playbook(test_path) assert result.returncode == 0 _tests[test_name] = method From 927329326c5de865bb536cfb91dfd4a0b37dbba0 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Thu, 11 Jun 2020 11:19:25 -0300 Subject: [PATCH 2/2] Reformatted README for better presentation on 80 column terminals. --- tests/README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/README.md b/tests/README.md index 2e12bd4b..d187575e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,11 +2,9 @@ ## Before starting -In order to run ansible-freeipa tests you will need to have `ansible` and `pytest` -installed on your machine. We'll call this local machine `controller`. +In order to run ansible-freeipa tests you will need to have `ansible` and `pytest` installed on your machine. We'll call this local machine `controller`. -You will also need to have a remote host with freeipa server installed and configured. -We'll call this remote host `ipaserver`. +You will also need to have a remote host with freeipa server installed and configured. We'll call this remote host `ipaserver`. Some other requirements: @@ -19,27 +17,32 @@ Some other requirements: ## Running the tests To run the tests run: + ``` IPA_SERVER_HOST= pytest ``` If you need to run using a different user you can use `ANSIBLE_REMOTE_USER` environment variable. For example: + ``` ANSIBLE_REMOTE_USER=root IPA_SERVER_HOST= pytest ``` To select which tests to run use the option `-k`. For example: + ``` IPA_SERVER_HOST= pytest -k dnszone ``` To see the ansible output use the option `--capture=sys`. For example: + ``` IPA_SERVER_HOST= pytest --capture=sys ``` To see why tests were skipped use `-rs`. For example: + ``` IPA_SERVER_HOST= pytest -rs ``` @@ -52,3 +55,4 @@ For a complete list of options check `pytest --help`. * A script to pre-config the complete test environment using virsh. * A test matrix to run tests against different distros in parallel (probably using tox). * Allow to connect to `ipaserver` using ssh and password. +