Write use cases, test execution main:
IF the __name__ == ' __main__ ' :
Print ( ' ha ah ha aha ' )
Loader = unittest.TestLoader ()
# Suite = loader.loadTestsFromTestCase (TestKtp) # Both are good
Suite = loader.loadTestsFromModule ( ' test_case_ktp ' )
path = os.path.abspath with (the os.path.join (The os.getcwd (), ' .. ' , ' Report ' , ' ktp_report4.html ' ))
with Open (path, ' WB ') AS File:
Runner = HTMLTestRunner_cn.HTMLTestRunner (= File Stream, verbosity = 2, title = ' classroom school logon test ' ,
the Description = ' on landing tests with a different account password ' )
runner.run (Suite)
Module run or executed:
import os
import sys
# sys.path.append(os.path.dirname(os.path.dirname(__file__)))
sys.path.append(os.path.abspath(os.path.join(os.getcwd(), '..')))
import unittest
from test_case.test_case_ktp import TestKtp
from common import HTMLTestRunner_cn
from test_case import test_case_ktp
from tool import read_excel
# loader = unittest.TestLoader()
# # suite = loader.loadTestsFromTestCase(TestKtp) # 这种行,下面不行
#= loader.loadTestsFromModule Suite ( 'test_case_ktp')
Suite = unittest.TestSuite () # with Example warehouse
suite.addTest (TestKtp ( ' test_login ' )) # TestMathMethod parent class initialization function, and shall participate = methodName 'the runTest'
path = os.path.abspath with (the os.path.join (The os.getcwd (), ' .. ' , ' Report ' , ' ktp_report5.html ' ))
with Open (path, ' WB ' ) AS File:
Runner = HTMLTestRunner_cn. HTMLTestRunner (= File Stream, the verbosity = 2, title = 'Login classroom school test ',
The Description = ' on landing tests with a different account password ' )
runner.run (Suite)
Find:
In which the main HTMLTestRunner unittest manner by running test is not a test report
must be run as a file name, a loader loaded with the embodiment can be FromTestCase FromModule and, outside the module or FromTestCase cases to run with a load,
but not with FromModule case, but not given, when added with the suite = unittest.testsuite (), suite.addTest ( TestKtp ( 'test_login')) with the embodiment, whether in
or executed in the run are given in the main module in the outside of the module I do not know why !!! is always been this way and I still run the code related to the environment, is not known.