calling class variable via method from robot framework prints empty list

眉间皱痕 提交于 2020-01-25 06:39:27

问题


Python version: 3.7.8 Robot framework: 3.1.2

I have a python class where specified a class variable to store and retrieve data later in robot framework.

Example: class1

class test1():
   __testvar__=[]

   def set_data(self, data):
      test1.__testvar__.append(data)

   def get_data(self)
      return test1._testvar__

   def main_calling_method(self):
      ...something...
      self.set_data(data)

class2:

from ...test1 import test1
class test2():
   t=test1()

   def get_method_data(self)
      return test2.t.main_calling_method()

Robot framework: Robot1 File :

*** Settings ***
Library   Pathto\test2.py

*** Keywords ***

 callingkeyword
 ${body}=  get_method_data
 [RETURN]  ${body}

 main keyworkd
 ${response}=  callingkeyword
 [RETURN]  ${response}

Robot2 File:

*** Settings ***
Resoure Pathto\Robot1.robot
Library Pathto\test1.py

*** Keywords ***
testing
${temp}=  main keyworkd
${data}=  get_data
log to console  ${data}

Expected Results:- Value of class variable --testvar__ to be printed in console

Actual Results:- Prints empty list.

If I run the method 'get_data' from python, it prints the data that are added as part of set_data but not producing the same results while running from robot framework.

However, if I call set method like below, before calling get_method, then prints the data properly.

  *** Keywords ***
    testing
    ${temp}=  main keyworkd
    set_data=  testing
    ${data}=  get_data
    log to console  ${data}

Could you please assist where the issue is?

Note: The above scenarios are dummy code for understanding purpose only as I can't share the actual project codes due to security concerns.


回答1:


Seems like you didn't put any data into the class, so you didn't get any output when printing. But in the second part code you showed, where you called "set_data= testing" (I suppose this 'testing' is another keyword you customed?), seems like it put the data into the class, so you can print it out.



来源:https://stackoverflow.com/questions/59534664/calling-class-variable-via-method-from-robot-framework-prints-empty-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!