You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enhance documentation related to importing same library multiple times #5122
According to the user guide, "If a library is imported multiple times with different arguments, a new instance is created every time regardless the scope."
But that does not seem to work for me.
Here is the example test case I use:
*** Settings ***Library testlib.py num=1 AS Test
Library testlib.py num=2 AS Test
Library testlib.py num=3 AS Test
*** Test Cases ***Example Test
Log Params
BuiltIn.Import Library ${CURDIR}/testlib.py num=4 AS Test
Log Params
As I import the library each time with a different argument, I would expect, that a new instance of the library is created that overwrites the current instance. Instead, the very first instance of the library seems to be used as the output of both calls of Log Params is 1.
Did I understand the note in the user guide wrong or is this an unintended behaviour?
@pekkaklarck can we put this in the 7.3 scope? I think that improving the documentation to make it clear that either it is undefined which of the loaded libraries is going to be used, or that it is going to be the first would be a low risk low effort medium win activity worth doing.
We can try enhancing docs related to this in RF 7.3. Behavioral changes need to wait for RF 8.0.
I have provided a PR for the doc improvement and am happy to react to input and guidance there, but I do not feel comfortable committing to delivering code for a behavior change.
changed the title [-]Multiple imports of library does not create new instance[/-][+]Enhance documentation related to importing same library multiple times[/+]on Mar 7, 2025
I just commented the documentation changes that @franzhaas proposed in PR #5301. Do you @oetzus have opinions about that? Do you see other places where this could be clarified better?
The underlying problem in the original example is that although the library is imported with different arguments, it is always imported with the same alias. That means that the library gets the same name and that causes the latter imported libraries to me ignored. If aliases would be different, for example Test1, Test2, Test3 and Test4, then execution would fail in the first Log Params call like this:
Multiple keywords with name 'Log Params' found. Give the full name of the keyword you want to use:
Test1.Log Params
Test2.Log Params
Test3.Log Params
Silently ignoring imported libraries isn't great and should be changed. The same think happens also if you import a library multiple times without an alias, regardless do you use different arguments or not. We have had plans to change the import logic in RF 8.0, but I believe we could emit a warning already in RF 7.4 in these cases. I'll submit a separate issue about that and ask opinion from others on the #devel channel on our Slack. Even if we agree a warning is a good idea, it probably makes sense to check what the User Guide says about this.
After #5492 being implemented, running the original example gives you three warnings like this:
[ WARN ] Error in file '/path/to/example.robot' on line 3: Suite 'Example' has already imported library 'Test' with different arguments. This import is ignored.
These warnings ought to make it clear that subsequent imports are ignored, so there are less needs to document this behavior in detailed level.
The above said, I noticed that the User Guide section about providing arguments to libraries (it's the section before the section about library scopes linked from the description, and the library scope section has a link to it as well) didn't mention the need to use custom names if same library is imported multiple times. I'll enhance that section in this regard. I believe that, in combination with the new warning, is enough to consider this issue done.
Activity
franzhaas commentedon Dec 30, 2024
When you try this you will see that there is a new instance created every time.
Together with this robot file you can achieve what you are aiming for.:
The documentation does not state explicitly which of those loaded library instances will be accessible via the name/be the global instance.
franzhaas commentedon Jan 16, 2025
@pekkaklarck can we put this in the 7.3 scope? I think that improving the documentation to make it clear that either it is undefined which of the loaded libraries is going to be used, or that it is going to be the first would be a low risk low effort medium win activity worth doing.
pekkaklarck commentedon Feb 11, 2025
We can try enhancing docs related to this in RF 7.3. Behavioral changes need to wait for RF 8.0.
franzhaas commentedon Feb 19, 2025
I have provided a PR for the doc improvement and am happy to react to input and guidance there, but I do not feel comfortable committing to delivering code for a behavior change.
[-]Multiple imports of library does not create new instance[/-][+]Enhance documentation related to importing same library multiple times[/+]pekkaklarck commentedon Apr 6, 2025
I just commented the documentation changes that @franzhaas proposed in PR #5301. Do you @oetzus have opinions about that? Do you see other places where this could be clarified better?
pekkaklarck commentedon Aug 28, 2025
The underlying problem in the original example is that although the library is imported with different arguments, it is always imported with the same alias. That means that the library gets the same name and that causes the latter imported libraries to me ignored. If aliases would be different, for example Test1, Test2, Test3 and Test4, then execution would fail in the first
Log Paramscall like this:Silently ignoring imported libraries isn't great and should be changed. The same think happens also if you import a library multiple times without an alias, regardless do you use different arguments or not. We have had plans to change the import logic in RF 8.0, but I believe we could emit a warning already in RF 7.4 in these cases. I'll submit a separate issue about that and ask opinion from others on the #devel channel on our Slack. Even if we agree a warning is a good idea, it probably makes sense to check what the User Guide says about this.
pekkaklarck commentedon Sep 2, 2025
After #5492 being implemented, running the original example gives you three warnings like this:
These warnings ought to make it clear that subsequent imports are ignored, so there are less needs to document this behavior in detailed level.
The above said, I noticed that the User Guide section about providing arguments to libraries (it's the section before the section about library scopes linked from the description, and the library scope section has a link to it as well) didn't mention the need to use custom names if same library is imported multiple times. I'll enhance that section in this regard. I believe that, in combination with the new warning, is enough to consider this issue done.
Enhance documentation related to importing same library multiple times