Skip to content

Library with custom __dir__ and attributes implemented via __getattr__ causes crash #5368

@JanDubcak

Description

@JanDubcak

Hello folks,
If I use faker library (python version) with RF7 and higher. There is an error during runtime, while importing the library.
However the library is imported successfully if RF6 is used.
Since the time to upgrade to latest and greatest has come, I have tried and found myself stuck on this issue.

RF & Python version: Robot Framework 7.2.2 (Python 3.13.2 on win32)
OS: Windows 11 Enterprise, Version: 23H2, OS build: 22631.4890, Installed on: 10. ‎7. ‎2024

Steps to reproduce:

  • Install robotframework
    pip install robotframework==7.2.2
    pip install faker
  • Create test a case that uses faker
*** Settings ***
Library         faker.Faker    sk-SK

*** Test Cases ***
Do nothing
    Sleep    1s
  • Run the test case
$ robot robot-faker.robot
[ ERROR ] Unexpected error: AttributeError: aba
Traceback (most recent call last):
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\utils\application.py", line 81, in _execute
    rc = self.main(arguments, **options)
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\run.py", line 475, in main
    result = suite.run(settings)
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\model.py", line 802, in run
    self.visit(runner)
    ~~~~~~~~~~^^^^^^^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\model\testsuite.py", line 421, in visit
    visitor.visit_suite(self)
    ~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\model\visitor.py", line 128, in visit_suite
    if self.start_suite(suite) is not False:
       ~~~~~~~~~~~~~~~~^^^^^^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\suiterunner.py", line 81, in start_suite
    ns.handle_imports()
    ~~~~~~~~~~~~~~~~~^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\namespace.py", line 57, in handle_imports
    self._handle_imports(self._imports)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\namespace.py", line 68, in _handle_imports
    self._import(item)
    ~~~~~~~~~~~~^^^^^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\namespace.py", line 76, in _import
    action(import_setting)
    ~~~~~~^^^^^^^^^^^^^^^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\namespace.py", line 124, in _import_library
    lib = IMPORTER.import_library(name, import_setting.args,
                                  import_setting.alias, self.variables)
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\importer.py", line 54, in import_library
    lib.create_keywords()
    ~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\testlibraries.py", line 326, in create_keywords
    StaticKeywordCreator(self, avoid_properties=True).create_keywords()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\testlibraries.py", line 373, in create_keywords
    kw = self._create_keyword(instance, name)
  File "C:\Users\jan.dubcak\robot-faker\robot-faker\Lib\site-packages\robot\running\testlibraries.py", line 460, in _create_keyword
    candidate = inspect.getattr_static(instance, name)
  File "C:\Users\jan.dubcak\AppData\Local\Programs\Python\Python313\Lib\inspect.py", line 1863, in getattr_static
    raise AttributeError(attr)
AttributeError: aba
  • Downgrade to RF 6.1.1
    pip install robotframework==6.1.1
  • Run the test case again
$ robot robot-faker.robot
==============================================================================
Robot-Faker
==============================================================================
Do nothing                                                            | PASS |
------------------------------------------------------------------------------
Robot-Faker                                                           | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Output:  C:\Users\jan.dubcak\robot-faker\output.xml
Log:     C:\Users\jan.dubcak\robot-faker\log.html
Report:  C:\Users\jan.dubcak\robot-faker\report.html

Kind thanks for anyone looking at this,
Jan.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions