diff --git a/plugin-template b/plugin-template index 84ec91bf..ea33caf3 100755 --- a/plugin-template +++ b/plugin-template @@ -13,6 +13,7 @@ from pathlib import Path import yaml from jinja2 import Environment, FileSystemLoader +from packaging.requirements import Requirement import utils @@ -345,11 +346,40 @@ def main(): file_path = os.path.join(plugin_root_dir, "template_config.yml") print("\nAn updated plugin template config written to {path}.\n".format(path=file_path)) + if "github" in sections: + migrate_pytest_plugins(plugin_root_dir) + if plugin_root_dir: print("\nDeprecation check:") check_for_deprecated_files(plugin_root_dir, sections) +def migrate_pytest_plugins(plugin_root_dir): + with open(f"{plugin_root_dir}/functest_requirements.txt", "r") as fp: + lines = fp.readlines() + modified = False + for item in ["pytest-xdist", "pytest-timeout"]: + found = False + result = [] + for line in lines: + try: + req = Requirement(line) + except ValueError: + result.append(line) + continue + if req.name == item: + found = True + result.append(line) + if not found: + result.append(f"{item}\n") + modified = True + lines = result + + if modified: + with open(f"{plugin_root_dir}/functest_requirements.txt", "w") as fp: + fp.writelines(lines) + + def to_nice_yaml(data): """Implement a filter for Jinja 2 templates to render human readable YAML.""" return yaml.dump(data, indent=2, allow_unicode=True, default_flow_style=False) diff --git a/templates/github/.github/workflows/scripts/script.sh.j2 b/templates/github/.github/workflows/scripts/script.sh.j2 index f31e5865..81aff089 100755 --- a/templates/github/.github/workflows/scripts/script.sh.j2 +++ b/templates/github/.github/workflows/scripts/script.sh.j2 @@ -135,13 +135,13 @@ else if [[ "$GITHUB_WORKFLOW" =~ "Nightly" ]] then {%- for plugin in plugins %} - cmd_user_prefix bash -c "pytest -v -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m parallel -n {{ parallel_test_workers }} --nightly" - cmd_user_prefix bash -c "pytest -v -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m 'not parallel' --nightly" + cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m parallel -n {{ parallel_test_workers }} --nightly" + cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m 'not parallel' --nightly" {%- endfor %} else {%- for plugin in plugins %} - cmd_user_prefix bash -c "pytest -v -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m parallel -n {{ parallel_test_workers }}" - cmd_user_prefix bash -c "pytest -v -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m 'not parallel'" + cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m parallel -n {{ parallel_test_workers }}" + cmd_user_prefix bash -c "pytest -v --timeout=300 -r sx --color=yes --suppress-no-test-exit-code --pyargs {{ plugin.name | snake }}.tests.functional -m 'not parallel'" {%- endfor %} fi fi diff --git a/templates/test/functest_requirements.txt.j2 b/templates/test/functest_requirements.txt.j2 index 5aecac20..acea38ee 100644 --- a/templates/test/functest_requirements.txt.j2 +++ b/templates/test/functest_requirements.txt.j2 @@ -1,2 +1,4 @@ pulp-smash @ git+https://github.com/pulp/pulp-smash.git pytest +pytest-xdist +pytest-timeout