如何从具有多个类的python文件导入自定义类

2024-09-30 12:12:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python类,我的class.py包含2个类。在

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

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

我想在robot框架中实现这两个类 如何实施?在

我试过这样的方法:

^{pr2}$

错误:导入测试库'我的班。我的班1'失败:ImportError:没有名为myclass的模块


Tags: 方法pytestself框架def错误robot
1条回答
网友
1楼 · 发布于 2024-09-30 12:12:10

我只试过用你的密码

Python文件我的class.py

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

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

机器人文件

^{pr2}$

快跑

输出

==============================================================================
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)在库中给出文件名/类名时,需要考虑大小写

相关问题 更多 >

    热门问题