Description
To illustrate I'll describe my scenario.
I've created a custom Robotframework Resource module (packaged independently using Poetry etc. for distribution) which contains user keywords and resource files. Resource files not only refer to Robotframework Resource
files, but any file required by the user keywords internal implementation.
I've followed the guidance provided on https://forum.robotframework.org/t/sharing-common-robot-framework-code/6977/1
In my example, the user keyword wraps an RPC style API where the contract is defined by an IDL file. The API uses binary serialisation and the IDL file is used to generate the codec for use internally.
My first naive approach used the standard Robotframework directory structure, cases, resources etc. The IDL file was referenced in the user keywords using a path relative to ${CURDIR}. This then failed when executed in a Robotframework execution environment which had the module installed.
To work around this, I added a Python utility to my Resource project, to read the file from a module on the Python Path.
return importlib.resources.read_text(
module_name, file_name, encoding=encoding, errors=errors
)
Disclaimer: I'm a Python novice ;-)
This utility was then used in the user keyword.
This has the advantage of not relying on a search of the path that may result in a file with the same name being found elsewhere.
Conveniently, using the importlib
, allowed support for different distribution, installation scenarios, e.g. downloads from pypi repo, install via *.tar.gz etc.
I've found #3317 but there's no progress on this yet.
Given the above, it may be useful to add a keyword similar to Get File
from OperationSystem
, to do the equivalent from a file in a module.
Thanks.