2016-11-30 77 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()