Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Dynamically create robot keywords in Python

$
0
0

I have a python library that implements robot framework keywords.I'm trying to generate a test suite automatically given a yaml file, but can't get one of the steps to work.

This is the simplified code:

from robot.api import TestSuitefrom robot.api.deco import keywordimport yaml@keyword("Request Api Call")def request_api_call(request_type, api_url, query_params, headers, body, expected_status):    # Does the API call@keyword("Generate Robot Tests")def generate_robot_tests(test_cases, file_path):    suite = TestSuite(suite_name)    for test_case in test_cases:        test = suite.tests.create(test_case_name)        test.body.create_keyword('Request Api Call', args=[request_type_value, api_url_value, query_params_value, headers_value, body_value, expected_status_value])    return suite

The problem is in test.body.create_keyword. It doesn't recognize the Request Api Call keyword.

When I call that keyword directly from the .robot file which imports this python file, it works.I'm guessing it's some sort of scope problem, but not sure how to solve it.

What I'm trying to accomplish is to run each test individually (to get the separate logs and test results), so I thought I could create a Test Suite per yaml file and then a Test Case per entry in that yaml file.

Any ideas? Thank you!


Viewing all articles
Browse latest Browse all 13951

Trending Articles