Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,22 +656,27 @@ 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,
data: running.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,
Expand All @@ -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,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*** Settings ***
Library ./foo.py


*** Test Cases ***
Asdfasdf
Bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

from pytest_robotframework import keyword


@keyword
def foo(): ...


@keyword
def bar():
foo()
foo()
8 changes: 8 additions & 0 deletions tests/test_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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