From 265a19475034d065d13478df4299415f4ea53083 Mon Sep 17 00:00:00 2001 From: Robin Loesch Date: Wed, 18 Nov 2026 11:54:02 +0100 Subject: [PATCH] Turn the library into a package The keyword moves from RobotmkLibrary/__init__.py to RobotmkLibrary/keyword_monitoring/__init__.py; the package re-exports it, so Library RobotmkLibrary keeps working, and Library RobotmkLibrary.keyword_monitoring imports the keyword monitoring keywords alone. The README documents the keyword. robotframework becomes a dependency, and an integration test pins the keyword list of the package through libdoc. pytest joins the dev tools and the workflow; mypy checks the tests too, with calls into the untyped robot package excluded from disallow_untyped_calls and the Any-typed values it returns tolerated in tests. --- .github/workflows/tests.yaml | 4 +- README.md | 21 +++++ pyproject.toml | 23 +++++- src/RobotmkLibrary/__init__.py | 17 ++--- .../keyword_monitoring/__init__.py | 20 +++++ tests/__init__.py | 0 tests/integration/__init__.py | 0 tests/integration/test_library.py | 14 ++++ uv.lock | 76 +++++++++++++++++++ 9 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 src/RobotmkLibrary/keyword_monitoring/__init__.py create mode 100644 tests/__init__.py create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/test_library.py diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 12eef98..c0ce1f4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,4 +31,6 @@ jobs: - run: uv run ruff check - - run: uv run mypy src + - run: uv run mypy src tests + + - run: uv run pytest diff --git a/README.md b/README.md index 05d50b7..bbbd316 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ A keyword library for Robot Framework intended to be used in combination with Robotmk. + +## Keywords + +```robotframework +*** Settings *** +Library RobotmkLibrary +``` + +| Keyword | Effect | +| --- | --- | +| `Monitor Subsequent Keyword Runtime discover_as=` | logs the marker that makes Checkmk discover the runtime of the next keyword, under its own name or the given one | + +### Development + +```sh +uv sync +uv run ruff format --diff +uv run ruff check +uv run mypy src +uv run pytest +``` diff --git a/pyproject.toml b/pyproject.toml index 0ec4274..4ccfd9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,9 @@ authors = [ { name = "Jörg Herbel", email = "joerg.herbel@checkmk.com" } ] requires-python = ">=3.11" -dependencies = [] +dependencies = [ + "robotframework>=7.5.1", +] [build-system] requires = ["hatchling"] @@ -16,6 +18,7 @@ build-backend = "hatchling.build" [dependency-groups] dev = [ "mypy>=2.4.1", + "pytest>=9.2", "ruff>=0.17.3", ] @@ -30,6 +33,9 @@ ignore = [ "TC", ] +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["PLR2004", "S101"] + [tool.mypy] strict = true enable_error_code = [ @@ -39,6 +45,21 @@ enable_error_code = [ ] disallow_any_expr = true disallow_any_explicit = true +# Calls into these packages are untyped at their end, not ours. +untyped_calls_exclude = ["robot"] + +[[tool.mypy.overrides]] +module = "tests.*" +# Robot Framework and the SDK hand the tests Any-typed values (run results, span ids). +disallow_any_expr = false + +[[tool.mypy.overrides]] +module = "robot.*" +ignore_missing_imports = true + +[tool.pytest.ini_options] +testpaths = ["tests"] +filterwarnings = ["error::UserWarning"] [tool.hatch.build.targets.wheel] packages = ["src/RobotmkLibrary"] diff --git a/src/RobotmkLibrary/__init__.py b/src/RobotmkLibrary/__init__.py index 3425b4e..7655eb6 100644 --- a/src/RobotmkLibrary/__init__.py +++ b/src/RobotmkLibrary/__init__.py @@ -1,14 +1,9 @@ -import logging +"""Keyword library for Robot Framework suites run by Robotmk. -logger = logging.getLogger(__name__) +``Library RobotmkLibrary`` imports the keywords, which live in +``RobotmkLibrary.keyword_monitoring``. +""" +from RobotmkLibrary.keyword_monitoring import monitor_subsequent_keyword_runtime -def monitor_subsequent_keyword_runtime( - *, - discover_as: str | None = None, -) -> None: - logger.info( - "The subsequent keyword will be discovered in Checkmk using its own name" - if discover_as is None - else f'The subsequent keyword will be discovered in Checkmk as: "{discover_as}"', - ) +__all__ = ["monitor_subsequent_keyword_runtime"] diff --git a/src/RobotmkLibrary/keyword_monitoring/__init__.py b/src/RobotmkLibrary/keyword_monitoring/__init__.py new file mode 100644 index 0000000..c8ea040 --- /dev/null +++ b/src/RobotmkLibrary/keyword_monitoring/__init__.py @@ -0,0 +1,20 @@ +"""Keywords for the runtime monitoring of the Checkmk test services.""" + +import logging + +logger = logging.getLogger(__name__) + + +def monitor_subsequent_keyword_runtime( + *, + discover_as: str | None = None, +) -> None: + """Log the marker that makes Checkmk discover the runtime of the next keyword.""" + logger.info( + "The subsequent keyword will be discovered in Checkmk using its own name" + if discover_as is None + else f'The subsequent keyword will be discovered in Checkmk as: "{discover_as}"', + ) + + +__all__ = ["monitor_subsequent_keyword_runtime"] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/test_library.py b/tests/integration/test_library.py new file mode 100644 index 0000000..249e128 --- /dev/null +++ b/tests/integration/test_library.py @@ -0,0 +1,14 @@ +"""The library as Robot Framework itself loads it.""" + +from robot.libdoc import LibraryDocumentation + + +def test_the_library_lists_the_runtime_keyword() -> None: + """Library RobotmkLibrary exposes exactly the keyword monitoring keyword. + + libdoc loads the package as Robot Framework does. Outcome: the keyword list + is Monitor Subsequent Keyword Runtime only. + """ + assert [ + keyword.name for keyword in LibraryDocumentation("RobotmkLibrary").keywords + ] == ["Monitor Subsequent Keyword Runtime"] diff --git a/uv.lock b/uv.lock index 025af0f..788da60 100644 --- a/uv.lock +++ b/uv.lock @@ -70,6 +70,24 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/11/25/4235f4b375a67a37ac595bf478a5407a744eaf7b64113c1c3a5432b8d954/ast_serialize-0.13.1-cp39-abi3-win_arm64.whl", hash = "sha256:48f11d96c9ec71119612f8e79a8c55c12f2b136716d68347433c561d27a25f43", size = 1139035, upload-time = "2026-10-17T00:04:15.767Z" }, ] +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/e1/2069291243c926a2ff1cd706c7f3eeb9b62144bf60f77c9fb9ff2fb26bd3/iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960", size = 21209, upload-time = "2026-10-06T22:48:38.076Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" }, +] + [[package]] name = "librt" version = "0.16.0" @@ -255,6 +273,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b5/99/7b1adac7e97ce7bbda34792dc6e9b2f5cc5cffd1875883f78a818b2a2687/mypy_extensions-1.2.0-py3-none-any.whl", hash = "sha256:993e7a20aa5671eb41a7132cf555af30062da99729601601b9a8382b11cae768", size = 5114, upload-time = "2026-11-03T16:26:32.731Z" }, ] +[[package]] +name = "packaging" +version = "26.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/7d/fa/3944b40b07da9ce895c0e6303a5ab7d53da063554f534556b134a54d6093/packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79", size = 313412, upload-time = "2026-08-04T18:15:28.737Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/63/34/ba1c580383c9eada3711951fef0795c80b829a078d72188184bcab9dd527/packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c", size = 129956, upload-time = "2026-08-04T18:15:27.159Z" }, +] + [[package]] name = "pathspec" version = "1.1.1" @@ -264,22 +291,71 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f1/d9/7fb5aa316bc299258e68c73ba3bddbc499654a07f151cba08f6153988714/pathspec-1.1.1-py3-none-any.whl", hash = "sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189", size = 57328, upload-time = "2026-04-27T01:46:07.06Z" }, ] +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/db/7fc19e6f2dc92a966727031389fc2e08b558f0f25eb7403c1119ad4713cd/pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8", size = 123304, upload-time = "2026-10-15T09:50:58.343Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/40/9e/2b38731e0fc536806f16490e1a12d7f0dc2a1235aa8cc07bcc75416a7daa/pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec", size = 27082, upload-time = "2026-10-15T09:50:56.808Z" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" }, +] + +[[package]] +name = "pytest" +version = "9.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/79/42/bb4641652e58dedeac2ec51abc1f8cae4fee4ec63899a0999016229a0f2a/pytest-9.2.0.tar.gz", hash = "sha256:97c4f3b1f3c7414aa36465e09b8220f1d03627993bd51b1282e193753c80557b", size = 1797555, upload-time = "2026-10-27T21:30:20.728Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/39/1f5d8c8877a0fa327db959c19341d4be61660de1ab6b7391f9eb805bcd67/pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588", size = 411776, upload-time = "2026-10-27T21:30:19.131Z" }, +] + +[[package]] +name = "robotframework" +version = "7.5.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/99/82/c7e3f8acb173c63e17cbdffdadf95a55520c0139cc548ce9ac963424361b/robotframework-7.5.1.tar.gz", hash = "sha256:00f63dc7b0477a137f8a9c1f2e14db8084a4d187a76f3fec6c2567875c32b932", size = 686670, upload-time = "2026-11-02T21:35:34.339Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2b/a3/6d528a8ac42a03ba4b9f6642b80ea37de2d18086d458c044bb6a6a8df5b9/robotframework-7.5.1-py3-none-any.whl", hash = "sha256:a46196098d92a30cb8b68c426d8d9a35b048d7936fc2cd9959b8c5c6f57524c8", size = 844474, upload-time = "2026-11-02T21:35:32.447Z" }, +] + [[package]] name = "robotframework-robotmklibrary" version = "0.0.4" source = { editable = "." } +dependencies = [ + { name = "robotframework" }, +] [package.dev-dependencies] dev = [ { name = "mypy" }, + { name = "pytest" }, { name = "ruff" }, ] [package.metadata] +requires-dist = [{ name = "robotframework", specifier = ">=7.5.1" }] [package.metadata.requires-dev] dev = [ { name = "mypy", specifier = ">=2.4.1" }, + { name = "pytest", specifier = ">=9.2" }, { name = "ruff", specifier = ">=0.17.3" }, ]