From 512f5dfc27397cae436d9fc2e82aa055fc89d31a Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Tue, 28 Sep 2021 16:51:35 +0200 Subject: [PATCH] Better error message for FileNotFoundErrors (#755) * Better error message for FileNotFoundErrors * Update tests/test_versions_yml.py Co-authored-by: James A. Fellows Yates * Update test_versions_yml.py Co-authored-by: James A. Fellows Yates --- tests/test_versions_yml.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/test_versions_yml.py b/tests/test_versions_yml.py index c3944a0f..b6392b87 100644 --- a/tests/test_versions_yml.py +++ b/tests/test_versions_yml.py @@ -2,6 +2,7 @@ from pathlib import Path import pytest import yaml import re +from textwrap import dedent def _get_workflow_names(): @@ -21,7 +22,22 @@ def _get_workflow_names(): def test_ensure_valid_version_yml(workflow_dir): workflow_dir = Path(workflow_dir) software_name = workflow_dir.name.split("_")[0].lower() - versions_yml = (workflow_dir / f"output/{software_name}/versions.yml").read_text() + try: + versions_yml_file = workflow_dir / f"output/{software_name}/versions.yml" + versions_yml = versions_yml_file.read_text() + except FileNotFoundError: + raise AssertionError( + dedent( + f"""\ + `versions.yml` not found in the output directory. + Expected path: `{versions_yml_file}` + + This can have multiple reasons: + * The test-workflow failed before a `versions.yml` could be generated. + * The workflow name in `test.yml` does not start with the tool name. + """ + ) + ) assert ( "END_VERSIONS" not in versions_yml @@ -29,7 +45,9 @@ def test_ensure_valid_version_yml(workflow_dir): # Raises an exception if yaml is not valid versions = yaml.safe_load(versions_yml) - assert len(versions) == 1, "The top-level of versions.yml must contain exactely one entry: the process name as dict key" + assert ( + len(versions) == 1 + ), "The top-level of versions.yml must contain exactly one entry: the process name as dict key" software_versions = next(iter(versions.values())) assert len(software_versions), "There must be at least one version emitted." for tool, version in software_versions.items():