Skip to main content

pytest-in-robotframework

pytest-in-robotframework enables the running of pytest within the Robot Framework, allowing users to leverage the advantages of both frameworks.

To achieve this integration, simply add the decorator '@pytest_execute' above all the pytest fixtures within your Python tests/keywords in python libraries.

The test with the '@pytest_execute' decorator will be executed within the pytest framework in the background. All the functionalities of the pytest framework should work normally, including fixture resolution, parametrization, etc. The final result from pytest will be passed on to the Robot Framework. If the specified keyword in the Robot Framework suite/test case fails, it will be logged as a failure in the Robot Framework results, along with the pytest console output as an info-message.

At present, this code serves as a proof of concept but is already fully usable in production.

It works with both, functions and methods, as long as they follow the naming conventions required by pytest (start or end with 'test'). The classes have to folow the naming convention of pytest (start with 'Test').

The decorator '@pytest_execute' should not compromise any pytest functionality. This means that original pytest tests, where this decorator is added in the Python file and executed via pytest, should continue to function as intended.

However, to utilize this feature, it is anticipated that the test will be primarily executed by Robot Framework, with only a few keywords executed by Pytest under the hood. Additionally, this feature might serve as a step-by-step tool for transitioning tests between Robot Framework and Pytest.

Installation and Usage

Command line installation:

pip install pytest-in-robotframework

Import and usage:

from pytest_in_robotframework import pytest_execute

#usage with functions
@pytest_execute
def test_my_function():
    assert  False

def rf_keyword_2():
        print('Passed')

#usage with methods 
class TestMyWorld: 

    @pytest_execute
    def test_my_method(self):
        assert  True

    def rf_keyword_1(self):
        print('Passed')

Real Example

Robot Framework file:

#The Example of usage  - suite_name.robot file

*** Settings ***
Documentation     Proof of Concept integration pytest under the hood of Robot Framework
Library  TestExperiment.py


*** Test Cases ***
Login User with Password
    Open Web Page  https://www.saucedemo.com/ #executed by RF
    Test Login As  user  password  #executed by Pytest under the hood

    #user and password is there only for Robot Framework checks (is not used)

Python File:

#The Example of usage  - TestExperiment.py file
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

#import of this solution
from pytest_in_robotframework import pytest_execute 

class TestExperiment:
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    driver = webdriver.Chrome(options=options)

    #executed by RF (becouse no @pytest_execute)
    def open_web_page(self,page): 
        self.driver.get(page)

    #executed by Pytest (becouse @pytest_execute decorator)
    @pytest_execute
    #@pytest.mark.parametrize("user,password", [("standard_user", "secret_sauce"),("locked_out_user", "secret_sauce"),("problem_user", "secret_sauce")]) #failing example
    @pytest.mark.parametrize("user,password", [("standard_user", "secret_sauce"),("problem_user", "secret_sauce")]) #passing example
    def test_login_as(self,user,password):
        print("vykonal jsem prvni radek test_login_as...")
        time.sleep(1)
        username = self.driver.find_element(By.ID,'user-name')
        username.clear()
        username.send_keys(user)
        my_password = self.driver.find_element(By.ID,'password')
        my_password.clear()
        my_password.send_keys(password)
        time.sleep(1)
        login_button = self.driver.find_element(By.ID, 'login-button')
        login_button.click()
        print(__name__)
        time.sleep(1)
        button = self.driver.find_element(By.ID, 'react-burger-menu-btn')
        button.click()
        time.sleep(1)
        button = self.driver.find_element(By.ID, 'logout_sidebar_link')
        button.click()
        time.sleep(1)

The real example demonstrates the benefits of using a single Python instance. The instances of the TestExperiment class have one driver instance for both the Robot Framework and Pytest engines. Additionally, Pytest parametrization can be utilized, which is a significant advantage compared to Robot Framework. In Robot Framework, it is possible to use Test Templates, but the process is not as straightforward as with Pytest for small combinatoric tests (closer to property testing).

Sometimes Pytest is the appropriate choice, while at other times Robot Framework may be better suited. Now, you can seamlessly integrate both into a single Python instance with identical logging, minimal effort, and compatibility.

Future planed Improvments

  • Enhance pytest logging experiance within Robot Framework (similar structure to pytest_robotframework / pytest-robotframework)

  • Ensure compatibility with the Hypothesis package (property based testing addon for pytest).

  • Add posibility to rename keyword for Robot Framework (RF supports this, but it may not currently work with Pytest)

  • Add the decorator parameters to pytest execution with user parameterization.

  • Introduce the ability to execute pytest in a separate process, providing added convenience for users.

  • Enable the transfer of parameters from Robot Framework to pytest execution, such as log levels.

  • Are there any additional tips or suggestions you would like to share? Please feel free to let me know!

Support Me 💡

If this project has saved you time or made your day easier, why not buy me a coffee? ☕ Every contribution helps me stay motivated and keep improving the tool for users like you!

Buy Me a Coffee

🙏 With your support, I can dedicate more time to developing new features, improving existing tools, and creating new resources—all in my free time after regular work. Your donations not only inspire me to continue but also show me that this tool has real users who want me to keep improving and supporting it.

You can also support me in the following ways:

  • Directly through GitHub Sponsors (or look for the heart on my profile).
  • ⭐ Add a star to this project.
  • 👀 Watch the project.
  • 📝 Leave bug reports or suggestions for new features.

💖 Thank You for considering supporting my work!

Release files for pytest-in-robotframework 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-in-robotframework 0.0.14
File Size Uploaded
pytest_in_robotframework-0.0.14.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-in-robotframework 0.0.14
File Interpreter ABI Platform
pytest_in_robotframework-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / pytest_in_robotframework-0.0.14.tar.gz

Download URL pytest_in_robotframework-0.0.14.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
02582b34fa04d507a16ba1d551e3ea9973e539c6ac6e970b034592a0e8c02028
BLAKE2b-256 checksum
How to use checksums
514c9631080c5ae0e5ccf336de1072aaf5f8750d8ed0515630bf8b3223fa6a43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / pytest_in_robotframework-0.0.14-py3-none-any.whl

Download URL pytest_in_robotframework-0.0.14-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b34a6c2f5b9471bb4fc0c80912ac8d301e8ec69d007ebd516fd5b680e0cd45a5
BLAKE2b-256 checksum
How to use checksums
ee06aaefc3e9c9aee4ca4cc88cab42e4c4767564eee626f5ba2c97f67f59a55d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.14 This release

2 release files

0.0.12

2 release files

0.0.9

2 release 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