在我当前的项目中,我们使用RobotFramework测试不同的OCU。现在,我在目录“ A”中有一个python包,其中包含__init__.py
和其他各种python文件。此程序包中至少有一个名为test
的函数。
我的机器人文件test.robot
看起来像这样:
*** Settings ***
Library A
*** Test Case ***
ExampleTest
A.test
当我在命令行下使用以下命令启动robot.exe时:
robot test.robot
我获得以下消息:
Importing test library 'A' failed: ModuleNotFoundError: No module named '.'
我在这里做错了什么?
给出以下文件夹结构。
User:[git/stackoverflow]# ll
total 448
drwxrwxrwx 1 root root 4096 May 27 21:59 ./
drwxrwxrwx 1 root root 4096 May 27 21:55 ../
drwxrwxrwx 1 root root 4096 May 27 21:58 A/
-rwxrwxrwx 1 root root 152 May 27 21:59 test.robot*
User:[git/stackoverflow]# cd A
User:[stackoverflow/A]# ll
total 0
drwxrwxrwx 1 root root 4096 May 27 21:58 ./
drwxrwxrwx 1 root root 4096 May 27 21:59 ../
-rwxrwxrwx 1 root root 0 May 27 21:55 __init__.py*
-rwxrwxrwx 1 root root 28 May 27 21:58 other.py*
User:[stackoverflow/A]#
其中other.py是:
from robot.libraries.BuiltIn import BuiltIn
def test():
BuiltIn().log_to_console("Logging from A.other test function")
test.robot是:
*** Settings ***
Library A.other WITH NAME MYLIB
*** Test Cases ***
Example Test
Log To Console Example test running
MYLIB.test
您可以像这样运行它:
User:[git/stackoverflow]# robot --pythonpath ./ test.robot
==============================================================================
Test
==============================================================================
Example Test Example test running
.Logging from A.other test function
Example Test | PASS |
------------------------------------------------------------------------------
Test | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: /mnt/c/Users/ebenkau/git/stackoverflow/output.xml
Log: /mnt/c/Users/ebenkau/git/stackoverflow/log.html
Report: /mnt/c/Users/ebenkau/git/stackoverflow/report.html
User:[git/stackoverflow]#
说明:
您必须从目录A导入python文件,该目录包含功能test
,例如A.other
。然后,您可以调用other.py中定义的任何函数作为关键字。同样,如果other.py中有一个类,则必须像A.other.someClass
一样导入它才能调用其函数。确保在pythonpath中有A
,这是通过在我的情况下使用--pythonpath ./
参数实现的。