Skip to content

[QUESTION] What is the best practice of handling RobotFramework libraries with complex __init__ functions #602

@MikeAckerschott

Description

@MikeAckerschott

Please describe.
Im currently working in a codebase in which we use python files as robotframework libraries within robottests. Our codebase is quite big and complex, and i assumed that was one of the reasons why RobotCodes analysis was quite slow, but i didnt experience this slowness in different projects. After some trial and error i found out that by default, RobotCode's analyse function runs the __init__ function of imported libraries. This means that a project with the following 2 files:

*** Settings ***
Library    main.ExampleLibrary

*** Test Cases ***
Example test
    Log To Console  message=Hello, World!
import time
from robot.api.deco import keyword

class ExampleLibrary:
    ''' Does some complex stuff in the init function'''
    
    def __init__(self):
        time.sleep(100)

will in fact take 100 seconds to return the RobotCode analysis result. Now I'm unsure whether this is intended, but if it is, what would be the best practice to avoid these type of situations? Should libraries expose a keyword that handles complex initialization to avoid excessive runtime duration of the RobotCode analyse function? Thanks

Desktop (please complete the following information):

  • VS Code Version [e.g. 1.117.0]
  • RobotCode Version [2.5.1]
  • OS: [Windows 11]
  • Python Version [3.11.9]
  • RobotFramework Version [7.4.2]
  • robocop Version [8.2.7]

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions