From 123df084b3d9fd1872c39aa6f88112351a693c4c Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Wed, 8 Jul 2020 15:49:12 +0200 Subject: [PATCH] Tests: Don't trip over added toddlers Relax some tests so that they cope with added toddlers without having to update the relevant tests. Signed-off-by: Nils Philippsen --- tests/plugins/test_plugins.py | 22 ++++++++-------------- tests/test_runner.py | 16 ++++++++-------- toddlers/plugins/__init__.py | 3 +++ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/tests/plugins/test_plugins.py b/tests/plugins/test_plugins.py index 2502066..80706f1 100644 --- a/tests/plugins/test_plugins.py +++ b/tests/plugins/test_plugins.py @@ -2,17 +2,11 @@ import toddlers.plugins def test_toddlers_plugins(): - variables = [var for var in dir(toddlers.plugins) if not var.startswith("__")] - assert sorted(variables) == sorted( - [ - "debug", - "flag_ci_pr", - "flag_commit_build", - "here", - "importlib", - "name", - "os", - "packager_bugzilla_sync", - "pdc_retired_packages", - ] - ) + plugin_module_names = toddlers.plugins.__all__ + assert not any(n.startswith("__") for n in plugin_module_names) + assert { + "flag_ci_pr", + "flag_commit_build", + "packager_bugzilla_sync", + "pdc_retired_packages", + } <= set(plugin_module_names) diff --git a/tests/test_runner.py b/tests/test_runner.py index d6b776b..c31a8fe 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -23,14 +23,14 @@ class TestRunningToddler: @patch_messaging_config() def test___init__(self): runner = toddlers.runner.RunningToddler() - assert sorted([t.name for t in runner.toddlers]) == sorted( - [ - "flag_ci_pr", - "flag_commit_build", - "packager_bugzilla_sync", - "pdc_retired_packages", - ] - ) + # Check that at least these toddlers exist (but don't fail + # automatically just because new ones are added). + assert { + "flag_ci_pr", + "flag_commit_build", + "packager_bugzilla_sync", + "pdc_retired_packages", + } <= {t.name for t in runner.toddlers} @patch_messaging_config() @patch("toddlers.runner.ToddlerBase") diff --git a/toddlers/plugins/__init__.py b/toddlers/plugins/__init__.py index bf84810..449525d 100644 --- a/toddlers/plugins/__init__.py +++ b/toddlers/plugins/__init__.py @@ -2,8 +2,11 @@ import importlib import os +__all__ = [] # fill below + here = os.path.abspath(os.path.dirname(__file__)) for name in os.listdir(here): if name.endswith(".py") and not name.startswith("__"): name = name[:-3] importlib.import_module(f".{name}", package=__name__) + __all__.append(name)