Hey all,
I’m trying to create a resource that relies on the API of a custom library, not a particular implementation of it. I need the suite initialization to determine which particular implementation will get imported, and ideally support passing arguments to the library. So I’ve tried a number of things:
Move arguments to Suite Setup:
That’s one option, but is quite verbose, and assumes GLOBAL
library scope:
# __init__.robot
*** Settings ***
Library ${LIBRARY_NAME} AS LIB
Setup Suite Setup Suite
*** Variables ***
${LIBRARY_NAME} MyLibrary.py
*** Keywords ***
Setup Suite
LIB.Init arg
# my.resource
*** Settings ***
Library ${LIBRARY_NAME} AS LIB
An intermediate resource:
Here's one similarly verbose solution that seems to work:# __init__.robot
*** Settings ***
Setup Suite Setup Suite
*** Variables ***
${MY_RESOURCE} my_lib.resource
# my_lib.resource
*** Settings ***
Library MyLibrary.py arg AS LIB
Resource my.resource
# my.resource
*** Keywords ***
One
LIB.Keyword
List expansion:
I was hoping for list expansion, but that doesn't seem to do:# __init__.robot
*** Variables ***
@{LIBRARY_AND_ARGS} MyLibrary.py arg
# my.resource
*** Settings ***
Library @{LIBRARY_AND_ARGS} AS LIB
# [ ERROR ] Error in file 'my.resource' on line 2: Importing library '['MyLibrary.py', 'arg']' failed: ModuleNotFoundError: No module named "['MyLibrary"
Suite Setup:
Nor does importing things in the suite setup steps:# __init__.robot
*** Settings ***
Library @{LIBRARY_AND_ARGS} AS LIB
Setup Suite Setup Suite
*** Keywords ***
Setup Suite
Import Library @{LIBRARY_AND_ARGS}
# my.resource
*** Keywords ***
One
LIB.Keyword
# No keyword with name 'LIB.Keyword' found.
Two
Keyword
# No keyword with name 'Keyword' found.
At this point I’m thinking the intermediate resource as the best solution, but am I missing something?
Thanks!