Skip to content

Emit warning if library is re-imported with different arguments #5492

Closed

Description

@pekkaklarck

At the moment if you import a library multiple times like

*** Settings ***
Library    Example
Library    Example

the library is imported every time, but latter imports are silently ignored because there's already a library imported with the same name. This is typically not a problem when a library accepts no arguments or if the library is used with same parameters, but in cases like

*** Settings ***
Library    Example    timeout=1
Library    Example    timeout=60

the latter import being silently ignored can cause a lot of confusion. In the above case it's easy to see there's something strange when both imports are in the same file, but the same problem occurs also if imports are, for example, in two different resource files that are both imported by a suite file.

As issue #5122 demonstrates, the problem with silently ignored imports occurs also when using import aliases if the same alias is reused.

To avoid these problems, I propose we start emitting a warning if a library is re-imported with the same name and the latter import is ignored. That way users immediately learn about ignored imports and can fix the situation.


UPDATE: The original design was changes so that now there's a warning only if a library is re-imported with different arguments.

Activity

  1. added this to the v7.4 milestone on Aug 29, 2025
  2. self-assigned this
    on Aug 29, 2025
  3. pekkaklarck commented on Aug 29, 2025

    @pekkaklarck
    MemberAuthor

    Although this change doesn't break any tests, I decided to label this issue as backwards incompatible. The reason is that there can be a lot of warnings and they can be somewhat distracting. For example, when I run Robot's own acceptance tests with a prototype implementation of this feature, there were ~50 warnings. Most of them were caused by two widely used resource files both importing the OperatingSystem library and fixing that simply required removing one of the imports. All these imports also used libraries without arguments and thus were harmless. If there turn out to be a huge number of such warnings during the preview release time, we can still consider changing the behavior so that we emit a warning only if a library is re-imported with arguments.

  4. changed the title [-]Emit warning if same library is imported multiple times[/-] [+]Emit warning if library is re-imported with different arguments[/+] on Sep 2, 2025
  5. pekkaklarck commented on Sep 2, 2025

    @pekkaklarck
    MemberAuthor

    Based on the discussion on Slack, I decided to change the design so that there's a warning only if a library is re-imported with different arguments. This avoids warnings in cases where a library like OperatingSystem is imported in different resource files used by one suite. Users are anyway informed about cases where library configuration is ignored because the library has already been imported using different config.

    I also decided to warn about cases where a library is imported using an alias that is used already by another library. Also in this case the latter import is ignored and it makes sense to inform users about that.

    After the aforementioned design change, I don't consider this at all backwards incompatible.

  6. added a commit that references this issue on Sep 2, 2025
    ede92c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions