Skip to content

Inconsistency importing "GLOBAL" library using "WITH NAME" with and without args #2931

Closed

Description

@cbrz

I'm seeing an inconsistency when importing libraries:

  • When importing a library with "ROBOT_LIBRARY_SCOPE" set to "GLOBAL" and using different "WITH NAME" values, I'm seeing only one instance when executing tests in Robot Framework.
  • When importing a different "GLOBAL" library but specifying arguments using different "WITH NAME" values, I'm seeing two instances when executing tests.

For replicating I have three files:
Files: robot_libimport.tar.gz

LibImport.py:

import logging

class LibImport(object):
    ROBOT_LIBRARY_SCOPE='GLOBAL'

    def __init__(self):
        self._name = None

    def set_name(self, value):
        self._name = value

    def log_name(self):
        logger = logging.getLogger(__name__)
        logger.info("name=%s", self._name)

LibImport2.py:

import logging

class LibImport2(object):
    ROBOT_LIBRARY_SCOPE='GLOBAL'

    def __init__(self, name):
        self._name = name

    def set_name(self, name):
        self._name = name

    def log_name(self):
        logger = logging.getLogger(__name__)
        logger.info("name=%s", self._name)

test.robot:

*** Settings ***
LIBRARY    ./LibImport.py    WITH NAME    libimport_1
LIBRARY    ./LibImport.py    WITH NAME    libimport_2
LIBRARY    ./LibImport2.py    value_1    WITH NAME    libimport2_1
LIBRARY    ./LibImport2.py    value_2    WITH NAME    libimport2_2

*** Test Cases ***
Incremenent And Log Count For LibImport.py
    libimport_1.Set Name    libimport_1
    libimport_2.Set Name    libimport_2

    libimport_1.Log Name
    libimport_2.Log Name

Incremenent And Log Count For LibImport2.py
    libimport2_1.Set Name    libimport_1
    libimport2_2.Set Name    libimport_2

    libimport2_1.Log Name
    libimport2_2.Log Name

To replicate I'm just running this:
robot -L trace test.robot

What I'm seeing is that the log keyword for LibImport.py will show "libimport_2" for both instances, while the ones for LibImport2.py will show "libimport_1", and "libimport_2" for the respective instances.

I took a quick look, and this seems happening when setting the import cache but I haven't had time to really test that theory.

For this case, I was actually hoping the library using LibImport2.py was the expected behavior. I was planning that as a workaround for the current framework I have. My main concern is using that workaround and watching everything break if I upgrade 😄.

Activity

  1. pekkaklarck commented on Aug 14, 2018

    @pekkaklarck
    Member

    I don't remember the details without looking at the code, but I'm fairly certain this behavior is by design. When you have a library that has a global scope, Robot avoids creating new instances, but when you take it into use with different arguments, that's just not possible.

  2. pekkaklarck commented on Aug 14, 2018

    @pekkaklarck
    Member

    This is to some extend related to #2106. The design can be reconsidered but definitely not in RF 3.1.

  3. pekkaklarck commented on Oct 3, 2018

    @pekkaklarck
    Member

    Nothing will be done for this in the near future and we already have related #2106. I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions