Skip to content

Commit

Permalink
use my keyword decorator for the keyword in robot_library.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Nov 18, 2023
1 parent e0d8864 commit 0afedcd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
14 changes: 4 additions & 10 deletions pytest_robotframework/_internal/robot_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def parse(self, source: Path, defaults: TestDefaults) -> running.TestSuite:
test_case.body = [
_create_running_keyword(
"KEYWORD",
robot_library.internal_error, # type:ignore[no-any-expr]
robot_library.internal_error,
Cloaked[str](
"fake placeholder test appeared. this should never happen :(("
),
Expand Down Expand Up @@ -220,27 +220,21 @@ def start_suite(self, suite: running.TestSuite):
# TODO: whats this mypy error
# https://github.com/DetachHead/pytest-robotframework/issues/36
test.setup = _create_running_keyword( # type:ignore[assignment]
"SETUP",
robot_library.setup, # type:ignore[no-any-expr]
cloaked_item,
"SETUP", robot_library.setup, cloaked_item
)

item.stash[original_body_key] = test.body # type:ignore[misc]
test.body = Body(
items=[
_create_running_keyword(
"KEYWORD",
robot_library.run_test, # type:ignore[no-any-expr]
cloaked_item,
"KEYWORD", robot_library.run_test, cloaked_item
)
]
)

item.stash[original_teardown_key] = test.teardown
test.teardown = _create_running_keyword(
"TEARDOWN",
robot_library.teardown, # type:ignore[no-any-expr]
cloaked_item,
"TEARDOWN", robot_library.teardown, cloaked_item
)


Expand Down
18 changes: 9 additions & 9 deletions pytest_robotframework/_internal/robot_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from _pytest._code.code import TerminalRepr
from _pytest.runner import call_and_report, show_test_item
from pytest import Item, StashKey, TestReport
from robot.api.deco import keyword
from robot.libraries.BuiltIn import BuiltIn

from pytest_robotframework import keyword
from pytest_robotframework._internal import cringe_globals
from pytest_robotframework._internal.errors import InternalError
from pytest_robotframework._internal.pytest_exception_getter import exception_key
Expand Down Expand Up @@ -65,8 +65,8 @@ def _call_and_report_robot_edition(
)


@keyword # type:ignore[no-any-expr,misc]
def setup(arg: Cloaked[Item]): # type:ignore[no-any-decorated]
@keyword
def setup(arg: Cloaked[Item]):
item = arg.value
cringe_globals._current_item = item # noqa: SLF001
# mostly copied from the start of `_pytest.runner.runtestprotocol`:
Expand All @@ -80,8 +80,8 @@ def setup(arg: Cloaked[Item]): # type:ignore[no-any-decorated]
_call_and_report_robot_edition(item, "setup")


@keyword # type:ignore[no-any-expr,misc]
def run_test(arg: Cloaked[Item]): # type:ignore[no-any-decorated]
@keyword
def run_test(arg: Cloaked[Item]):
item = arg.value
# mostly copied from the middle of `_pytest.runner.runtestprotocol`:
reports = item.stash[_report_key]
Expand All @@ -96,8 +96,8 @@ def run_test(arg: Cloaked[Item]): # type:ignore[no-any-decorated]
_call_and_report_robot_edition(item, "call")


@keyword # type:ignore[no-any-expr,misc]
def teardown(arg: Cloaked[Item]): # type:ignore[no-any-decorated]
@keyword
def teardown(arg: Cloaked[Item]):
item = arg.value
# mostly copied from the end of `_pytest.runner.runtestprotocol`:
_call_and_report_robot_edition(
Expand All @@ -106,6 +106,6 @@ def teardown(arg: Cloaked[Item]): # type:ignore[no-any-decorated]
cringe_globals._current_item = None # noqa: SLF001


@keyword # type:ignore[no-any-expr,misc]
def internal_error(msg: Cloaked[str]): # type:ignore[no-any-decorated]
@keyword
def internal_error(msg: Cloaked[str]):
raise InternalError(msg.value)

0 comments on commit 0afedcd

Please sign in to comment.