Skip to content

Improve test and doc repeated imports - #5301

Closed
franzhaas wants to merge 6 commits into
robotframework:masterfrom
franzhaas:improve_test_and_doc_repeated_imports
Closed

franzhaas wants to merge 6 commits into
robotframework:masterfrom
franzhaas:improve_test_and_doc_repeated_imports

Conversation

@franzhaas

@franzhaas franzhaas commented Jan 1, 2025 •

Copy link
Copy Markdown
Contributor

this issue reminded me that there is a wired situation that is a bit hard to understand and might benefit from a more verbose documentation

When you load the same library repeated times on the same "AS" name.
All of them get performed from top to button
But the initial one is accessible under the name.
The same applies when using Import Library

Doing this is in my point of view not a good idea. However, documenting this property would have helped me when analyzing/debugging in the past.

There is a risk by documenting this to make this behavior a requirement hindering future developments. In that case it would be a reasonable alternative to declare the behaviour undefined. The problem for me is that the sentence.:

If a library is imported multiple times with different arguments, a new instance is created every time regardless the scope.

can be misunderstood to imply that the created instance is also assigned.

@franzhaas
franzhaas marked this pull request as draft January 1, 2025 13:56
@franzhaas
franzhaas marked this pull request as ready for review January 1, 2025 14:16
@franzhaas

Copy link
Copy Markdown
Contributor Author

I noticed the added test was not run at all at CI. I fixed that. I also moved the test to the core tests.

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the current behavior isn't already covered by tests? I would be surprised if it wasn't, but I can certainly be wrong.

See also my comment about the documentation change.

a new instance is created every time regardless the scope.
a new instance is created every time regardless the scope. If a
library is imported multiple times using the same destination
the initial instance remains available unaffected by the new imports.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed wording, especially "same destination" sounds a bit odd for me. Could it something like this be better:

If a library is imported multiple times using same arguments, subsequent imports are ignored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that subsequent imports do not get ignored. If they would get ignored, and ideally a warning generated, the situation would be much better.

They do happen, and the __init__ code gets executed, which leaves robotframework in a Frankenstein situation where the global state of the last, and the object of the first import attempt to work together, which is confusing at least.

It gets worse when while debugging someone reads the logs buttom up. The newest __init__ call is found first, and both global and object state are logged in a consistent state, adding to the confusion.

I think this is unintuitive, and I believe it should be clearly documented.

If multiple destinations are used, the situation becomes much less confusing, as there are multiple objects, one of which is consistent with global state, the others are not. This bug behaves in robotframework the same way as it would in python, much easier to deal with.

If no global state is involved with multiple destinations, the behaviour is actually the way I would expect it to be.

@franzhaas

Copy link
Copy Markdown
Contributor Author

Are you sure the current behavior isn't already covered by tests? I would be surprised if it wasn't, but I can certainly be wrong.

I do not know. I did not spend a lot of time looking for preexisitng tests for this topic, but I did not stumble on them.

@franzhaas franzhaas closed this Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants