a pytest plugin to generate robotframework reports without having to write your tests in the robot langauge
Project description
pytest-robotframework
a pytest plugin to generate robotframework reports without having to write your tests in the robot langauge
install
poetry add pytest-robotframework --group=dev
usage
pytest should automatically find and activate the plugin once you install it, so all you should have to do is write tests with pytest like you would normally:
# you can use both robot and pytest features
from robot.api import logger
from pytest import Cache
from pytest_robotframework import keyword
@keyword # make this function show as a keyword in the robot log
def foo():
...
def test_foo(cache: Cache):
foo()
robot command line arguments
specify robot CLI arguments with the --robotargs argument:
pytest --robotargs="-d results --listener foo.Foo"
some arguments such as --extension obviously won't work .
setup/teardown and other hooks
to define a function that runs for each test at setup or teardown, create a conftest.py with a pytest_runtest_setup and/or pytest_runtest_teardown function:
# ./tests/conftest.py
def pytest_runtest_setup():
log_in()
# ./tests/test_suite.py
def test_something():
"""i am logged in now"""
these hooks appear in the log the same way that the a .robot file's Setup and Teardown options in *** Settings *** would:
for more information, see writing hook functions. pretty much every pytest hook should work with this plugin but i haven't tested them all. please raise an issue if you find one that's broken.
tags/markers
pytest markers are converted to tags in the robot log:
from pytest import mark
@mark.slow
def test_blazingly_fast_sorting_algorithm():
[1,2,3].sort()
markers like skip, skipif and parameterize also work how you'd expect:
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
robot suite variables
to set suite-level robot variables, call the set_variables function at the top of the test suite:
from robot.libraries.BuiltIn import BuiltIn
from pytest_robotframework import set_variables
set_variables(
{
"foo": "bar",
"baz": ["a", "b"],
}
)
def test_variables():
assert BuiltIn().get_variable_value("$foo") == "bar"
set_variables is equivalent to the *** Variables *** section in a .robot file. all variables are prefixed with $. @ and & are not required since $ variables can store lists and dicts anyway
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_robotframework-1.1.0.tar.gz.
File metadata
- Download URL: pytest_robotframework-1.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.4 Linux/5.15.0-1042-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaaa6b0004fc900ea604258bb914657eca4437c705a984524d48eb3d9ceae0b4
|
|
| MD5 |
5b32b7b828acdd5a6086522b1a16cb7d
|
|
| BLAKE2b-256 |
2c1f7a79c8c60ca1a22cc03041e63aa412c1e95bcf1c5d88a9051b93f4bad5f4
|
File details
Details for the file pytest_robotframework-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_robotframework-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.4 Linux/5.15.0-1042-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8a5ac4e4f0cdf7c629ecb715721894fc7e218e8d6f538b8a41db1ed2e45d0d7
|
|
| MD5 |
5e44277cb7223a903cfb6c758e157182
|
|
| BLAKE2b-256 |
41302ef29fbacb24e526f47699803f62649e918b3c981f24fe8374463579092e
|