mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
Currently, all tests are scheduled to execution, even those that are not executed due to being absent from the list of enabled tests configured in the IPA_ENABLED_* variables. The tests that are not executed are marked 'skipped'. This patch change this behavior by not scheduling tests that are not configured to be executed. It means that tests not the IPA_DISABLED_* lists are not skipped anymore, but not scheduled to be executed. If any test is in IPA_ENABLED_* lists, only those tests are marked for execution. A side effect is that there is no visual feedback on which tests were not executed, as disabled tests are not evaluated anymore. Also, when IPA_SERVER_HOST was not set, all tests were skipped, but an error should raised in this case, as there are no hosts to run the tests against. This patch modifies this behavior to fail the test with an exception if IPA_SERVER_HOST is not set.
79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
#!/usr/bin/env python
|
|
|
|
# Authors:
|
|
# Sergio Oliveira Campos <seocam@redhat.com>
|
|
#
|
|
# Copyright (C) 2020 Red Hat
|
|
# see file 'COPYING' for use and warranty information
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import pytest
|
|
import functools
|
|
|
|
from unittest import TestCase
|
|
|
|
from utils import (
|
|
get_test_playbooks, get_server_host, run_playbook, get_enabled_test,
|
|
get_disabled_test
|
|
)
|
|
|
|
|
|
def prepare_test(testname, testpath):
|
|
"""
|
|
Decorate tests generated automatically from playbooks.
|
|
|
|
Injects 2 arguments to the test (`test_path` and `test_name`) and
|
|
name the test method using test name (to ensure test reports are useful).
|
|
"""
|
|
def decorator(func):
|
|
@functools.wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
kwargs["test_path"] = testpath
|
|
kwargs["test_name"] = testname
|
|
return func(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
decorator.__name__ = testname
|
|
return decorator
|
|
|
|
|
|
if not get_server_host():
|
|
raise RuntimeError("IPA_SERVER_HOST is not set.")
|
|
|
|
# Dynamically create the TestCase classes with respective
|
|
# test_* methods.
|
|
for test_dir_name, playbooks_in_dir in get_test_playbooks().items():
|
|
_tests = {}
|
|
|
|
for playbook in playbooks_in_dir:
|
|
test_name = playbook["name"].replace("-", "_")
|
|
test_path = playbook["path"]
|
|
|
|
if (
|
|
get_enabled_test(test_dir_name, test_name)
|
|
and not get_disabled_test(test_dir_name, test_name)
|
|
):
|
|
# pylint: disable=W0621,W0640,W0613
|
|
@pytest.mark.playbook
|
|
@prepare_test(test_name, test_path)
|
|
def method(self, test_path, test_name):
|
|
run_playbook(test_path)
|
|
# pylint: enable=W0621,W0640,W0613
|
|
|
|
_tests[test_name] = method
|
|
|
|
globals()[test_dir_name] = type(test_dir_name, tuple([TestCase]), _tests,)
|