Python 2.7 测试用例运行两次而不是一次
此测试应该通过调用Python 2.7 测试用例运行两次而不是一次,python-2.7,nose,python-unittest,Python 2.7,Nose,Python Unittest,此测试应该通过调用TALogin.test()super方法登录用户,该方法传递凭据(URL、用户名/密码等),然后注销用户。但是,当我运行它时,它会运行TALogin部分,然后关闭并再次运行它,但会执行注销部分 因此,我得到以下信息: Ran 2 tests in 65.990s OK 我只想让它运行一次;登录,然后注销 这是我的密码: from BaseTestCase import BaseTestCase from pages.BasePage import BasePage fro
TALogin.test()
super方法登录用户,该方法传递凭据(URL、用户名/密码等),然后注销用户。但是,当我运行它时,它会运行TALogin
部分,然后关闭并再次运行它,但会执行注销部分
因此,我得到以下信息:
Ran 2 tests in 65.990s
OK
我只想让它运行一次;登录,然后注销
这是我的密码:
from BaseTestCase import BaseTestCase
from pages.BasePage import BasePage
from login.TALogin_Test import TALogin
import nose
class TALogout_Test(TALogin):
def setUp(self):
super(TALogout_Test, self).setUp()
def test(self):
super(TALogout_Test, self).test()
base_obj = BasePage(self.driver)
base_obj.do_logout()
def tearDown(self):
super(TALogout_Test, self).tearDown()
if __name__ == "__main__":
nose.run(defaultTest=__name__)
发生这种情况是因为您没有告诉
nose
您只想在TALogout\u Test
中运行测试。它同时运行TALogin.test
和TALogout\u test.test
指定要从中加载测试的类的一种方法是使用nose.run()
的suite
参数和unittest.TestLoader
的方法:
这是宾果游戏!谢谢
from unittest import defaultTestLoader
nose.run(suite=defaultTestLoader.loadTestsFromTestCase(TALogout_Test))