reportportal / agent-Python-RobotFramework

Robot Framework integration for Report Portal
Apache License 2.0
59 stars 32 forks source link

Listener does not work for Initialization files (__init__.robot) #64

Closed amarquezj closed 3 years ago

amarquezj commented 4 years ago

When using an initialization file (__init__.robot) for global setups and tear-downs all the keywords/actions performed inside these global setup and teardowns result on error, see below:

[ ERROR ] Calling method 'start_keyword' of listener 'robotframework_reportportal.listener' failed: IndexError: list index out of range

These happens as there is no suite attached as a parent due to init.robot being an special "test suite" not recognized as a test suite.

These can be fixed by modifying the listener.py file more specifically the start suite method (See below the method code and the fix between commented lines)

def start_suite(name, attributes):
    print("start suite:" + name)
    suite = Suite(attributes=attributes)
    print("robot id: " + suite.robot_id + " - name: "+ name)
    if suite.robot_id == "s1":
        Variables.check_variables()
        RobotService.init_service(Variables.endpoint, Variables.project,
                                  Variables.uuid)
        suite.doc = Variables.launch_doc
        logging.debug("ReportPortal - Start Launch: {0}".format(attributes))
        RobotService.start_launch(launch_name=Variables.launch_name,
                                  launch=suite)
        #-------------------------------------------------------------------
        #Used to display top level folder to contain global setups and teardowns
        logging.debug("ReportPortal - Create global Suite: {0}".format(attributes))
        parent_id = items[-1][0] if items else None
        item_id = RobotService.start_suite(name=name, suite=suite,
                                           parent_item_id=parent_id)
        items.append((item_id, parent_id))
       #-------------------------------------------------------------------------------

        if not suite.suites:
            attributes['id'] = "s1-s1"
            start_suite(name, attributes)

    else:
        logging.debug("ReportPortal - Start Suite: {0}".format(attributes))
        parent_id = items[-1][0] if items else None
        item_id = RobotService.start_suite(name=name, suite=suite,
                                           parent_item_id=parent_id)
        items.append((item_id, parent_id))
iivanou commented 4 years ago

Could you share a code that can be used to reproduce the issue?

bhirsz commented 3 years ago

I also encountered this issue and code from @amarquezj fixed it. To reproduce this you need __init__.robot file with suite setup or teardown. listener will try to register those keywords but it will fail since we don;t create suite for __init__ files (which is bug in my opinion).

example__init__.robot file

*** Settings ***
Suite Setup  Keyword

*** Keywords ***
Keyword
    No Operation

and test.robot file inside the same directory

*** Test Cases ***
Test
    Log  stuff

try to run test.robot file with listener

iivanou commented 3 years ago

Fixed in #93.