From 38c8b59fe03b2cf64f1ed497eb8eadc0591b29af Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 21 Dec 2025 16:55:06 +0100 Subject: [PATCH] test(integration): ignore **pycache** directories in role validation tests https://chatgpt.com/share/69481867-784c-800f-ab60-50ce3b241dd4 --- .../integration/test_roles_have_meta_main.py | 20 ++++++++++++++----- tests/integration/test_roles_naming.py | 8 ++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/integration/test_roles_have_meta_main.py b/tests/integration/test_roles_have_meta_main.py index b9591f2f95..cf7b044859 100644 --- a/tests/integration/test_roles_have_meta_main.py +++ b/tests/integration/test_roles_have_meta_main.py @@ -1,18 +1,28 @@ import os import unittest -ROLES_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../roles")) +ROLES_DIR = os.path.abspath( + os.path.join(os.path.dirname(__file__), "../../roles") +) class TestRolesHaveMetaMain(unittest.TestCase): def test_each_role_has_meta_main(self): missing_meta = [] + for role in os.listdir(ROLES_DIR): + # Ignore Python cache and hidden directories + if role.startswith(".") or role == "__pycache__": + continue + role_path = os.path.join(ROLES_DIR, role) - if os.path.isdir(role_path): - meta_main = os.path.join(role_path, "meta", "main.yml") - if not os.path.isfile(meta_main): - missing_meta.append(role) + if not os.path.isdir(role_path): + continue + + meta_main = os.path.join(role_path, "meta", "main.yml") + if not os.path.isfile(meta_main): + missing_meta.append(role) + if missing_meta: self.fail( "The following roles are missing meta/main.yml:\n" diff --git a/tests/integration/test_roles_naming.py b/tests/integration/test_roles_naming.py index bf4f39b0bc..ed92d8ea87 100644 --- a/tests/integration/test_roles_naming.py +++ b/tests/integration/test_roles_naming.py @@ -10,19 +10,23 @@ ROLE_NAME_PATTERN = re.compile(r"^[a-z0-9-]+(?:_[a-z0-9-]+)?$") class TestRoleNames(unittest.TestCase): def test_role_names_follow_naming_convention(self): - # go up from tests/integration/test_roles_naming.py to project root, then into roles/ roles_dir = Path(__file__).resolve().parents[2] / "roles" self.assertTrue( roles_dir.is_dir(), f"'roles/' directory not found at {roles_dir}" ) invalid_names = [] + for role_path in roles_dir.iterdir(): if not role_path.is_dir(): - # skip non-directories continue name = role_path.name + + # Ignore Python cache and hidden directories + if name.startswith(".") or name == "__pycache__": + continue + if not ROLE_NAME_PATTERN.fullmatch(name): invalid_names.append(name)