Skip to content
Open
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: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ score = "no"
max-line-length = 200

[tool.pytest.ini_options]
addopts = '-p no:robotframework'
addopts = ['-p no:robotframework', '--import-mode=importlib']
xfail_strict = true

[tool.mypy]
Expand Down
29 changes: 28 additions & 1 deletion tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,32 @@ def test_foo():
BuiltIn().run_keyword('bar')
"""
)
run_and_assert_result(pytester, passed=1)
run_and_assert_result(pytester, errors=1, pytest_args=["--import-mode=importlib"])
# we add the current directory to the syspath to simulate `py -m pytest`
pytester.syspathinsert(".")
run_and_assert_result(pytester, passed=1, pytest_args=["--import-mode=importlib"])
assert_log_file_exists(pytester)


def test_robot_keyword_in_python_test_prepend(pytester: Pytester):
pytester.makefile(
".resource",
bar="""
*** keywords ***
bar
log 1
""",
)
pytester.makepyfile( # type:ignore[no-untyped-call]
"""
from pytest_robotframework import import_resource
from robot.libraries.BuiltIn import BuiltIn

import_resource("bar.resource")

def test_foo():
BuiltIn().run_keyword('bar')
"""
)
run_and_assert_result(pytester, passed=1, pytest_args=["--import-mode=prepend"])
assert_log_file_exists(pytester)
7 changes: 6 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ def assert_log_file_exists(pytester: Pytester):
def run_pytest(
pytester: Pytester, *pytest_args: str, plugins: list[object] | None = None
) -> RunResult:
__traceback_hide__ = True
# TODO: figure out why robot doesn't use pytester's cd anymore. started happening when
# i added a test that calls a function from the plugin directly instead of using pytester
# https://github.com/DetachHead/pytest-robotframework/issues/38
return pytester.runpytest(
*pytest_args, "--robotargs", f"-d {pytester.path}", plugins=plugins or []
*pytest_args,
"--robotargs",
f"-d {pytester.path}",
plugins=plugins or [],
)


Expand All @@ -48,6 +52,7 @@ def run_and_assert_result(
failed=0,
errors=0,
):
__traceback_hide__ = True
result = run_pytest(pytester, *(pytest_args or []))
result.assert_outcomes(passed=passed, skipped=skipped, failed=failed, errors=errors)
assert_robot_total_stats(
Expand Down