如何从包含多个类的python文件导入自定义类

如何从包含多个类的python文件导入自定义类,python,robotframework,Python,Robotframework,我有一个python类myclass.py,它包含两个类 class MyTestClass1: def test1(self): print "Test 1" class MyTestClass2: def test1(self): print "Test 1" 我想在robot框架中实现这两个类 如何实施 我试过这样的方法: *** Settings *** Library myclass.MyTestClass1 Library mycl

我有一个python类myclass.py,它包含两个类

class MyTestClass1:
    def test1(self):
        print "Test 1"

class MyTestClass2:
    def test1(self):
        print "Test 1"
我想在robot框架中实现这两个类 如何实施

我试过这样的方法:

*** Settings ***
Library myclass.MyTestClass1
Library myclass.MyTestClass2

*** Test Cases ***
Test Case 1
    log  This is test case 1

错误:导入测试库“myclass.MyClass1”失败:导入错误:没有名为myclass的模块

我仅用您的代码进行了尝试

Python文件Myclass.py

class MyTestClass1:
    def test1(self):
        print "Test 1"

class MyTestClass2:
    def test1(self):
        print "Test 1"
机器人文件

*** Settings ***
Library    Myclass.MyTestClass1
Library    Myclass.MyTestClass2

*** Test Cases ***
Test Case 1
    log  This is test case 1
运行它

输出

==============================================================================
Myclassf
==============================================================================
Test Case 1                                                           | PASS |
------------------------------------------------------------------------------
Myclassf                                                              | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
执行过程中可能出现的问题

1) robot文件和Python文件可能不在同一文件夹中(这不是必需的,但如果两个文件位于不同的位置,则必须指定路径)


2) 在库中输入文件名/类名时,需要记住小写/大写字母

名称拼写错误。在myclass.py中有
MyTestCalss2
MyTestCalss2
,但在robot文件中使用的是
MyTest1
MyTest2
。感谢Bryan的回复,但这是一个打字错误。在我的实际代码中,这是正确的。您需要显示实际说明问题的代码。我看不到你的计算机上有什么。“你试图做的”不是python代码。这是伪代码吗??请附加您尝试的全部代码,因为这对于这个简单的示例来说不太可能……我有一个python类文件,我想在我的Robot框架中使用它。上面的示例包含一个python文件,其中包含两个类,我正在尝试在Robot框架中实现这些类。我也有同感。获取测试用例通过,但找到了错误-日志文件-(venv)C:\temp\robo>robot myrobo.robot文件“C:\temp\robo\myrobo.robot”中的[ERROR]错误:导入测试库“Myclass.MyTestClass1”失败:ModuleNotFoundError:没有名为“Myclass”的模块回溯(最近一次调用):None PYTHONPATH:C:\Tools\WorkSpace\PycharmProjects\RobotFramework\venv\Scripts\robot.exe C:\Tools\Python37\Python37.zip C:\Tools\Python37\DLLs C:\Tools\Python37\lib C:\Tools\Python37 C:\Tools\WorkSpace\Python37 C:\RobotFramework\venv C:\Tools\WorkSpace\..是python还是robotfile在同一文件夹中?是的。两者都在同一个文件夹中。C:\TEMP\ROBO Myclass.py myrobo.robot