RobotFramework系统关键字解决导入报错robot framework Importing test library "CustomLibrary" failed

看了网上一些教程,导入自定义系统关键字

在\Lib\site-packages\目录下创建自定义文件夹CustomLibrary

在CustomLibrary下面创建runbat.py,写入关键字

在CustomLibrary下面创建__init__.py,供robotframework加载使用

结果ride显示导入的CustomLibrary是红色(导入失败)

查看日志:Ride中,查看日志Tools-->View Ride Logs

20190823 15:35:38.329 [WARN]: Importing test library "CustomLibrary" failed

Traceback (most recent call last):
Importing test library 'CustomLibrary' failed: ModuleNotFoundError: No module named 'runbat'
Traceback (most recent call last):
File "D:\9998Python37\lib\site-packages\robotide\lib\robot\utils\importer.py", line 153, in _import
return __import__(name, fromlist=fromlist)
File "D:\9998Python37\lib\site-packages\CustomLibrary\__init__.py", line 1, in <module>
from runbat import Runbat
PYTHONPATH:
D:\9998Python37\Scripts
D:\9998Python37\python37.zip
D:\9998Python37\DLLs
D:\9998Python37\lib
D:\9998Python37
D:\9998Python37\lib\site-packages
D:\9998Python37\lib\site-packages\pip-19.1.1-py3.7.egg
D:\9998Python37\lib\site-packages\win32
D:\9998Python37\lib\site-packages\win32\lib
D:\9998Python37\lib\site-packages\Pythonwin
D:\9998Python37\lib\site-packages\robotide\spec
D:\9998Python37\lib\site-packages\robotide\lib
D:\9998Python37\lib\site-packages\robotide\contrib\testrunner\../../lib
D:\9998Python37\lib\site-packages\robotide\contrib\testrunner\../../lib
File "D:\9998Python37\lib\site-packages\robotide\spec\librarymanager.py", line 87, in _fetch_keywords
return get_import_result(path, library_args)
File "D:\9998Python37\lib\site-packages\robotide\spec\libraryfetcher.py", line 24, in get_import_result
lib = robotapi.TestLibrary(path, args)
File "D:\9998Python37\lib\site-packages\robotide\lib\robot\running\testlibraries.py", line 50, in TestLibrary
return_source=True)
File "D:\9998Python37\lib\site-packages\robotide\lib\robot\utils\importer.py", line 72, in import_class_or_module
self._raise_import_failed(name, err)
File "D:\9998Python37\lib\site-packages\robotide\lib\robot\utils\importer.py", line 109, in _raise_import_failed
raise DataError('\n'.join(msg))

 

解决办法:

发现在pythonpath中只到D:\9998Python37\lib\site-packages

于是,在__init__.py中修改导入方式,

from runbat import Runbat   ---->
from CustomLibrary.runbat import Runbat
posted @ 2019-08-23 15:42  James_Danni  阅读(3107)  评论(0编辑  收藏  举报