From 76aaf8ea9637abf01e00f078f369e640f59d48e6 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 23 Dec 2025 08:14:28 +1000 Subject: [PATCH 1/4] format robot files on save in vscode --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2e79470f..c1371851 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -36,6 +36,9 @@ "[toml][json][jsonc][yaml][markdown][github-actions-workflow]": { "editor.defaultFormatter": "dprint.dprint" }, + "[robotframework]": { + "editor.defaultFormatter": "d-biehl.robotcode" + }, "robotcode.testExplorer.enabled": false, "explorer.compactFolders": false, "search.exclude": { From 2d9df07d003dcc82c6136ae492d132c8ab1b831c Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 23 Dec 2025 08:20:07 +1000 Subject: [PATCH 2/4] fix keywords that get called from a `.py` file in a `.robot` test only appearing in the robot log on the first call --- .../robot/listeners_and_suite_visitors.py | 33 +++++++++++++++++-- .../__init__.py | 0 .../a.robot | 7 ++++ .../foo.py | 13 ++++++++ tests/test_robot.py | 8 +++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/__init__.py create mode 100644 tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/a.robot create mode 100644 tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/foo.py diff --git a/pytest_robotframework/_internal/robot/listeners_and_suite_visitors.py b/pytest_robotframework/_internal/robot/listeners_and_suite_visitors.py index 0ce316a9..793bfddd 100644 --- a/pytest_robotframework/_internal/robot/listeners_and_suite_visitors.py +++ b/pytest_robotframework/_internal/robot/listeners_and_suite_visitors.py @@ -656,6 +656,9 @@ class KeywordUnwrapper(ListenerV3): printed a second time since they would already have been printed in a child keyword """ + def __init__(self) -> None: + self.__original_keyword_stack = list[Function | None]() + @override def start_library_keyword( self, @@ -663,15 +666,17 @@ def start_library_keyword( implementation: running.LibraryKeyword, result: result.Keyword, # pylint:disable=redefined-outer-name ): + """replaces a decorated keyword for when it gets called from a `.robot` file""" if not isinstance(implementation, StaticKeyword): return - original_function: Function | None = getattr( + original_function = getattr( implementation.method, _keyword_original_function_attr, None ) - + self.__original_keyword_stack.append( + getattr(implementation.owner.instance, implementation.method_name, None) # pyright:ignore[reportAny] + ) if original_function is None: return - setattr( implementation.owner.instance, # pyright:ignore[reportAny] implementation.method_name, @@ -681,3 +686,25 @@ def start_library_keyword( else original_function ), ) + + @override + def end_library_keyword( + self, + data: running.Keyword, + implementation: running.LibraryKeyword, + result: result.Keyword, # pylint:disable=redefined-outer-name + ): + """ + after the keyword is finished, restore its original value. otherwise if it gets called + again from a `.py` file, it won't show up as a keyword in the robot log. + """ + if not isinstance(implementation, StaticKeyword): + return + original_keyword = self.__original_keyword_stack.pop() + if original_keyword is None: + return + setattr( + implementation.owner.instance, # pyright:ignore[reportAny] + implementation.method_name, + original_keyword, + ) diff --git a/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/__init__.py b/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/a.robot b/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/a.robot new file mode 100644 index 00000000..78ecedce --- /dev/null +++ b/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/a.robot @@ -0,0 +1,7 @@ +*** Settings *** +Library ./foo.py + + +*** Test Cases *** +Asdfasdf + Bar diff --git a/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/foo.py b/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/foo.py new file mode 100644 index 00000000..031bf9b5 --- /dev/null +++ b/tests/fixtures/test_robot/test_keyword_called_twice_in_robot_test/foo.py @@ -0,0 +1,13 @@ +from __future__ import annotations + +from pytest_robotframework import keyword + + +@keyword +def foo(): ... + + +@keyword +def bar(): + foo() + foo() diff --git a/tests/test_robot.py b/tests/test_robot.py index 061d22ed..33cc6879 100644 --- a/tests/test_robot.py +++ b/tests/test_robot.py @@ -342,3 +342,11 @@ def test_keyword_decorator_class_library(pr: PytestRobotTester): def test_pass_execution(pr: PytestRobotTester): pr.run_and_assert_result(passed=1) pr.assert_log_file_exists() + + +def test_keyword_called_twice_in_robot_test(pr: PytestRobotTester): + pr.run_and_assert_result(passed=1) + pr.assert_log_file_exists() + results = output_xml().xpath("//kw[@name='Run Test']/kw[@name='Bar']/kw[@name='Foo']") + assert isinstance(results, list) + assert len(results) == 2 From cb2b0d3d09845264213ca158e3e6ee8f2dc02fda Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 23 Dec 2025 08:42:50 +1000 Subject: [PATCH 3/4] remove hardcoded pythonversion from docs job now that we pin it using `.python-version` --- .github/workflows/docs.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index d6601cbd..debc24c6 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -34,8 +34,6 @@ jobs: fetch-depth: 0 # fetch all commits/branches - uses: actions/setup-python@v5 id: install_python - with: - python-version: 3.12 - name: Configure Git user run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" From 77c31e339753d90de7b97002541d393cca4821aa Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 23 Dec 2025 08:43:53 +1000 Subject: [PATCH 4/4] bump dprint plugins --- dprint.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dprint.json b/dprint.json index 5b3ed1f7..53e7f8b6 100644 --- a/dprint.json +++ b/dprint.json @@ -8,8 +8,8 @@ ".basedpyright/baseline.json" ], "plugins": [ - "https://plugins.dprint.dev/json-0.20.0.wasm", - "https://plugins.dprint.dev/markdown-0.19.0.wasm", + "https://plugins.dprint.dev/json-0.21.0.wasm", + "https://plugins.dprint.dev/markdown-0.20.0.wasm", "https://plugins.dprint.dev/toml-0.7.0.wasm", "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm" ]