2016-11-30 94 views
0

我在測試套件中添加了一些測試用例。現在我想有能力執行一些測試,而無需從測試套件中刪除任何測試。從Python unittest測試套件執行特定測試?

在下面的代碼中,我在testsuite中添加了三個方法testm1,testm2,testm3。 現在我想執行只說testm1和testm3的測試。

代碼:

import HTMLTestRunner 
import os 
import unittest 
from test.LoginTest import TestA 
from test.LandingTest import TestB 


def testsuite(): 


    execute_suite = unittest.TestSuite() 


    execute_suite .addTest(TestA('testm1')) 
    execute_suite .addTest(TestB('testm2')) 
    execute_suite .addTest(TestB('testm3')) 

    return execute_suite 

reportloc = os.getcwd() 
outfile = open(reportloc + "TestReport.html", "w") 
executor = HTMLTestRunner.HTMLTestRunner(stream=outfile, title="Test Report", description="Tests") 


executor.run(testsuite()) 

請建議。

+1

請發佈您的代碼,以便人們可以幫助您。您可以查看http://stackoverflow.com/questions/15971735/running-single-test-from-unittest-testcase-via-command-line –

+0

不清楚你在問什麼 – Shaun

+0

編輯的問題。 – RakeshKirola

回答

0

在您想要跳過的測試方法上使用註釋@unittest.skip

import unittest 

@unittest.skip("some comment") 
def test_my_function()