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 .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
},
"chat.commandCenter.enabled": false,
"dprint.path": ".vscode/dprint", // https://github.com/dprint/dprint/issues/859#issuecomment-3194102785
"ty.disableLanguageServices": true, // we use basedpyright's language server because it's more feature-complete
"basedpyright.disableLanguageServices": true,
"git.blame.editorDecoration.enabled": true,
"yaml.customTags": [
// for mkdocs config. see https://squidfunk.github.io/mkdocs-material/creating-your-site/?h=vscode#minimal-configuration
Expand Down
15 changes: 10 additions & 5 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ you can specify a `pytest_robot_modify_options` hook in your `conftest.py` to pr
from pytest_robotframework import RobotOptions
from robot.api.interfaces import ListenerV3

class Foo(ListenerV3):
...

class Foo(ListenerV3): ...


def pytest_robot_modify_options(options: RobotOptions, session: Session) -> None:
if not session.config.option.collectonly:
options["loglevel"] = "DEBUG:INFO"
options["listener"].append(Foo()) # you can specify instances as listeners, prerebotmodifiers, etc.
options["listener"].append(
Foo()
) # you can specify instances as listeners, prerebotmodifiers, etc.
```

note that not all arguments that the plugin passes to robot will be present in the `args` list. arguments required for the plugin to function (eg. the plugin's listeners and prerunmodifiers) cannot be viewed or modified with this hook
Expand Down Expand Up @@ -81,6 +84,7 @@ you may have existing `assert` statements in your codebase that are not intended
```py
from pytest_robotframework import AssertOptions, hide_asserts_from_robot_log


def test_foo():
# hide a single passing `assert` statement:
assert foo == bar, AssertOptions(log_pass=False)
Expand All @@ -98,9 +102,10 @@ you can also run pytest with the `--no-assertions-in-robot-log` argument to disa
```py
from pytest_robotframework import AssertOptions


def test_foo():
assert "foo" == "bar" # hidden from the robot log (when run with --no-assertions-in-robot-log)
assert "bar" == "baz", AssertOptions(log_pass=True) # not hidden
assert "foo" == "bar" # hidden from the robot log (when run with --no-assertions-in-robot-log)
assert "bar" == "baz", AssertOptions(log_pass=True) # not hidden
```

### customizing assertions
Expand Down
28 changes: 15 additions & 13 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ from pytest import Cache

from pytest_robotframework import keyword


@keyword # make this function show as a keyword in the robot log
def foo():
...
def foo(): ...


@mark.slow # markers get converted to robot tags
def test_foo():
Expand Down Expand Up @@ -40,18 +41,20 @@ which is roughly equivalent to the following python code:
# test_foo.py
from pytest import mark


@keyword
def foo():
logger.info("ran setup")


@fixture(autouse=True)
def setup():
foo()


@mark.asdf
@mark.key("value")
def test_bar():
...
def test_bar(): ...
```

## setup/teardown
Expand All @@ -62,15 +65,16 @@ in pytest, setups and teardowns are defined using fixtures:
from pytest import fixture
from robot.api import logger


@fixture
def user():
logger.info("logging in")
user = ...
yield user
logger.info("logging off")

def test_something(user):
...

def test_something(user): ...
```

under the hood, pytest calls the fixture setup/teardown code as part of the `pytest_runtest_setup` and and `pytest_runtest_teardown` hooks, which appear in the robot log like so:
Expand All @@ -86,9 +90,10 @@ pytest markers are converted to tags in the robot log:
```py
from pytest import mark


@mark.slow
def test_blazingly_fast_sorting_algorithm():
[1,2,3].sort()
[1, 2, 3].sort()
```

![](./images/tags-and-markers.png)
Expand All @@ -98,6 +103,7 @@ markers like `skip`, `skipif` and `parameterize` also work how you'd expect:
```py
from pytest import mark


@mark.parametrize("test_input,expected", [(1, 8), (6, 6)])
def test_eval(test_input: int, expected: int):
assert test_input == expected
Expand All @@ -113,12 +119,8 @@ to set suite-level robot variables, call the `set_variables` function at the top
from robot.libraries.BuiltIn import BuiltIn
from pytest_robotframework import set_variables

set_variables(
{
"foo": "bar",
"baz": ["a", "b"],
}
)
set_variables({"foo": "bar", "baz": ["a", "b"]})


def test_variables():
assert BuiltIn().get_variable_value("$foo") == "bar"
Expand Down
6 changes: 3 additions & 3 deletions docs/limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ if you want a function you wrote to show up as a keyword in the log, decorate it
```py
from pytest_robotframework import keyword


@keyword
def foo():
...
def foo(): ...
```

### pytest functions are patched by the plugin
Expand Down Expand Up @@ -65,7 +65,7 @@ or if the exception is conditionally raised, use a `try`/`except` statement like
try:
some_keyword_that_fails()
except SomeException:
... # ignore the exception, or re-raise it later
... # ignore the exception, or re-raise it later
```

the keyword will still show as failed in the log (as long as it's decorated with `pytest_robotframework.keyword`), but it won't effect the status of the test unless the exception is re-raised.
Expand Down
2 changes: 1 addition & 1 deletion pw.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[main]
requirements = ["uv==0.9.18"]
requirements = ["uv==0.10.9"]
hash = "45210da832f9626829457a65e9e7c4d0"
Loading