Pabot --prerunnodifer with datadriver test

hi all,
i may not search deeply in the forum or its not answered here yet, so sorry if it is.

I have a use case>

  • generate data into csv
  • run pabot --testlevelsplit on the datadriver test case on previously generated csv file

while i can separate the steps in jenkins pipeline, by

  • run python script to generate csv file with test cases
  • and then run pabot like pabot --processes X --testlevelsplit

I’d like to use prerunmodifier to generate CSV file for pabot first, so use basically one command to run both steps at once (I’d like to have my generic jenkins file clean out of not needed steps)
When trying:
pabot --processes 4 --testlevelsplit --prerunmodifier PythonLibs/GenerateCSVwithTestCases.py. only a one process is started.

Is there a way to run pabot with X processes, testlevelsplit on datadriver test case template where the test cases are basically generated in prerun modifier and then taken by pabot ?

I cannot use the “run setup only once” since CSV is already taken by pabot before its basically generated.

many thanks for tips or pointing me on the right place in documentation.
f.

Hi!

If I understood correctly, you’re using the robotframework-datadriver library to generate Data-Driven style tests. I’m not personally familiar with this library, but I quickly tested it by creating the following files:

test_suite.robot

Library           DataDriver    file=test_suite.csv
Test Template     Login With User And Password

*** Test Cases ***
Login with user ${username} and password ${password}    Default    UserData

*** Keywords ***
Login With User And Password
    [Arguments]    ${username}    ${password}
    Log Many    ${username}    ${password}

and

CSVGenerator.py

from robot.api import SuiteVisitor

class CSVGenerator(SuiteVisitor):
    def __init__(self, filename="test_suite.csv"):
        self.filename = filename

    def generate_csv(self):
        """Generates a CSV file with predefined test case data."""
        data = [
            ["*** Test Cases ***", "${username}", "${password}", "[Tags]", "[Documentation]"],
            ["Right user empty pass", "demo", "${EMPTY}", "1", "This is a test case documentation of the first one."],
            ["Right user wrong pass", "demo", "FooBar", "2,3,foo", "This test case has the Tags 2,3 and foo"],
            ["", "${EMPTY}", "mode", "1,2,3,4", "This test case has a generated name based on template name."],
            ["", "${EMPTY}", "${EMPTY}", "", ""],
            ["", "${EMPTY}", "FooBar", "", ""],
            ["", "FooBar", "mode", "foo,1", ""],
            ["", "FooBar", "${EMPTY}", "foo", ""],
            ["", "FooBar", "FooBar", "foo,2", ""]
        ]

        with open(self.filename, "w", newline="", encoding="utf-8") as file:
            writer = csv.writer(file, delimiter=";")
            writer.writerows(data)

        print(f"CSV file '{self.filename}' has been generated successfully.")

    def start_suite(self, suite):
        self.generate_csv()

When I run the command:
pabot --testlevelsplit --processes 4 --prerunmodifier CSVGenerator.py .
Pabot executes all 8 tests across four processes. So make sure that the --prerunmodifier module you’re using works correctly and writes the file as expected.

As you can see from the output
“CSV file ‘test_suite.csv’ has been generated successfully.”
the CSV file is actually written twice. This happens because the start_suite() method is called both in your root directory and in the test_suite.robot suite.

If this is an issue, you could add a flag to indicate whether the start_suite() method has already been called and the CSV file has been written.

Note! In Pabot version 4.1.0, the --pabotprerunmodifier argument was introduced. It is only called once in the main process and is not passed to subprocesses, unlike the standard --prerunmodifier argument.

I hope this helps! Feel free to ask if you need further assistance, and provide a more detailed description of the issue, including simplified code examples if possible.

2 Likes

great, thanks, it worsk just fine on my mac, need to retry on windows machine. seems like i just used wrong order of arguments. --pabotprerunmodifier. is exactly what I needed. thanks a lot again.

Great ! I solve my issue too!

Thanks for your solution.

Best Regard,
Frank
DGMEE