Skip to main content

pytest-robotframework

a pytest plugin that can run both python and robotframework tests while generating robot reports for them

install

pytest should automatically find and activate the plugin once you install it.

poetry add pytest-robotframework --group=dev

features

write robot tests in python

# 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():
    ...

@mark.slow  # gets converted to robot tags
def test_foo(cache: Cache):
    foo()

run .robot tests

to allow for gradual adoption, the plugin also runs regular robot tests as well:

*** Settings ***
test setup  setup

*** Test Cases ***
bar
    [Tags]  asdf  key:value
    no operation

*** Keywords ***
setup
    log  ran setup

which is roughly equivalent to the following python code:

# conftest.py
from robot.api import logger
from pytest_robotframework import keyword

def pytest_runtet_setup():
    foo()

@keyword
def foo():
    logger.info("ran setup")
# test_foo.py
from pytest import mark

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

robot options

specify robot CLI arguments with the --robotargs argument:

pytest --robotargs="-d results --listener foo.Foo"

or you could use the ROBOT_OPTIONS environment variable:

ROBOT_OPTIONS="-d results --listener foo.Foo"

however, arguments that have pytest equivalents should not set with robot as they will probably cause the plugin to behave incorrectly. for example, instead of pytest --robotargs="--include some_tag" you should use pytest -m some_tag.

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

image

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_robotframework-1.4.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_robotframework-1.4.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_robotframework-1.4.0.tar.gz.

File metadata

  • Download URL: pytest_robotframework-1.4.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.4 Linux/5.15.0-1041-azure

File hashes

Hashes for pytest_robotframework-1.4.0.tar.gz
Algorithm Hash digest
SHA256 191a2b2f2c61533a6fdced74853ea93386afadd44235dde82249289eb9cd16fd
MD5 1b6fff4f823c81c914acf3fc1e83324a
BLAKE2b-256 0c7f843097537ac26f509e0da44f33c0e5c93211056f370cbd671c592a95b34b

See more details on using hashes here.

File details

Details for the file pytest_robotframework-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_robotframework-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57075d97126077ff7fdfbdbbb1157c88213468c7f6f87705c70602e30808e197
MD5 a4ea9ede1f51cc01dbef998f8d080944
BLAKE2b-256 6037ed4f125429b4311682e6c90e39e769da6efbdfeff959a2120ec3841eb7fd

See more details on using hashes here.

Release history Release notifications | RSS feed

4.6.3

2 files

4.6.2

2 files

4.6.1

2 files

4.6.0

2 files

4.5.0

2 files

4.4.1.post1

2 files

4.4.1

2 files

4.4.0.post2

2 files

4.4.0.post1

2 files

4.4.0

2 files

4.3.2

2 files

4.3.1

2 files

4.3.0

2 files

4.2.6

2 files

4.2.5

2 files

4.2.4

2 files

4.2.3

2 files

4.2.2

2 files

4.2.1

2 files

4.2.0

2 files

4.1.4

2 files

4.1.3

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.3

2 files

4.0.2

2 files

4.0.1

2 files

4.0.0

2 files

3.2.1

2 files

3.2.0

2 files

3.1.1

2 files

3.1.0

2 files

3.0.1

2 files

3.0.0

2 files

2.5.2

2 files

2.5.1

2 files

2.5.0

2 files

2.4.0

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.10.3

2 files

1.10.2

2 files

1.10.1

2 files

1.10.0

2 files

1.9.0

2 files

1.8.3

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.0

2 files

This release

1.4.0 This release

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page