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.