【问题标题】:Test case running twice not once测试用例运行两次而不是一次
【发布时间】:2016-07-13 12:29:39
【问题描述】:

该测试应该通过调用TALogin.test() 超级方法来登录用户,该方法会传递凭据(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__)

【问题讨论】:

    标签: python-2.7 nose python-unittest


    【解决方案1】:

    发生这种情况是因为您没有告诉nose 您只想在TALogout_Test 中运行测试。它同时运行 TALogin.testTALogout_Test.test

    指定要从中加载测试的类的一种方法是使用nose.run()suite 参数和unittest.TestLoaderloadTestsFromTestCase() 方法:

    from unittest import defaultTestLoader
    nose.run(suite=defaultTestLoader.loadTestsFromTestCase(TALogout_Test))
    

    【讨论】:

    • 这是一个宾果游戏!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    相关资源
    最近更新 更多