Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在unittest框架中从另一个测试调用测试方法?_Python_Unit Testing_Selenium - Fatal编程技术网

Python 如何在unittest框架中从另一个测试调用测试方法?

Python 如何在unittest框架中从另一个测试调用测试方法?,python,unit-testing,selenium,Python,Unit Testing,Selenium,为了达到我的要求,我已经编写了类似于下面代码的代码,但我收到了错误消息 class Test(BaseSetup): def test_01_create_record(self): -- def test_02_edit_record(self): -- def test_03_delete_record(self): -- def test_04_verify_item_tab(self)

为了达到我的要求,我已经编写了类似于下面代码的代码,但我收到了错误消息

class Test(BaseSetup):

    def test_01_create_record(self):        
        --
    def test_02_edit_record(self):
        --
    def test_03_delete_record(self):   
        --
    def test_04_verify_item_tab(self):
        testObj=Test()
        testObj.test_01_create_record()
        do this....
        testObj.test_03_delete_record()        

if __name__ == '__main__':       
    unittest.main()
在这里,上述三种测试方法(测试_01、测试_02和测试_03)运行良好,但最后一个测试,即测试_04失败。它无法使用test_01创建记录(尽管它单独运行良好)。我在上次测试中收到以下错误消息

self.driver.find_element_by_xpath(self.content_tab_xpath).click()
AttributeError: 'NoneType' object has no attribute 'find_element_by_xpath'

上面的错误消息是针对第一个测试(test_01_create_record),我只在从另一个测试调用第一个测试方法时得到,但是当我单独运行它时,它工作得很好。知道我遗漏了什么吗?非常感谢

无需在其中创建类的实例,只需使用
self
引用实例即可:

def test_04_verify_item_tab(self):
    self.test_01_create_record()
    self.test_03_delete_record()

为什么要在类自己的方法中创建新的类实例?你认为self是什么?哦,太好了,我只需要调用self.test\u 01\u create\u record()。这里不需要创建类的实例。谢谢