Skip to content

Commit

Permalink
Add pytest timeout
Browse files Browse the repository at this point in the history
Abort functional tests after 5 minutes to catch a good stacktrace on
stuck situations.
  • Loading branch information
mdellweg committed Aug 28, 2024
1 parent 72f4b38 commit ece49c9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
30 changes: 30 additions & 0 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from pathlib import Path

import yaml
from jinja2 import Environment, FileSystemLoader
from packaging.requirements import Requirement

import utils

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions templates/github/.github/workflows/scripts/script.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions templates/test/functest_requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pulp-smash @ git+https://github.com/pulp/pulp-smash.git
pytest
pytest-xdist
pytest-timeout

0 comments on commit ece49c9

Please sign in to comment.