diff --git a/README.md b/README.md index c69306ec5..1180b0f6a 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,12 @@ The section is targeting to explain configure options and test cases depends on. Notice that configuration options in [config.yml](config.yml) can be overwritten by command line parameters. For example, to overwrite the `endpoint` option, we can use the `--endpoint` parameter while running the tests. +To avoid dirtying the repository, place the customized version of the +`config.yml` in any one of the places: + +- `$HARVESTER_TESTS_CONFIG` +- `$HOME/.config/harvester/tests/config.yml` + ### Deprecated Config Options - `do-not-cleanup` - `harvester_cluster_nodes` diff --git a/harvester_e2e_tests/conftest.py b/harvester_e2e_tests/conftest.py index 3f4bec056..85e0cde4e 100644 --- a/harvester_e2e_tests/conftest.py +++ b/harvester_e2e_tests/conftest.py @@ -15,6 +15,7 @@ # To contact SUSE about this file by physical or electronic mail, # you may find current contact information at www.suse.com +import os import pytest import yaml from datetime import datetime @@ -49,9 +50,36 @@ def check_depends(self, depends, item): DepMgr.checkDepend, DepMgr._check_depend = check_depends, DepMgr.checkDepend +def merge_config(): + """ + Merge two config files. The user config takes precedence over the default + config. + """ + + paths = [ + os.path.join(os.getcwd(), 'config.yml'), + os.getenv('HARVESTER_TESTS_CONFIG', None), + os.path.join(os.getenv('HOME'), '.config', 'harvester', 'tests', + 'config.yml') + ] + + config = {} + for path in paths: + if path: + try: + with open(path, 'r') as cnf: + data = yaml.safe_load(cnf) + except FileNotFoundError: + data = {} + + config.update(data) + + return config + + def pytest_addoption(parser): - with open('config.yml') as f: - config_data = yaml.safe_load(f) + config_data = merge_config() + parser.addoption( '--endpoint', action='store', @@ -421,3 +449,18 @@ def pytest_html_results_table_header(cells): def pytest_html_results_table_row(report, cells): cells.insert(1, f'