求大神解决,已困扰两天,python,unittest测试结果为Ran 0 tests in 0.000s

时间:2022-09-16 18:19:21

testadd_run.py

#coding=utf-8
import unittest
from match_ import Match

class Test_match(unittest.TestCase):

    def setUp(self):
        print("start test")
    def test_add(self):
        t = Match(3,4)
        add=t.add()
        self.assertEqual(add,7,msg="运行成功")
        print("case1")

    def test_add2(self):
        t = Match(5,4)
        add = t.add()
        self.assertEqual(add, 9, msg="运行失败")
        print("case2")
    def tearDown(self):
        print("test end")

if __name__=="__main__":
    #unittest.main()
    suit=unittest.TestSuite
    suit.addTest(Test_match("test_add"))
    suit.addTest(Test_match("test_add2"))

    runner = unittest.TextTestRunner()
    runner.run(suit)
testsub_run.py

#coding=utf-8
import unittest
from match_ import Match
class TestMatchsub(unittest.TestCase):
    def setUp(self):
        print("test start:")
    def tearDown(self):
        print("test end")
    def test_sub(self):
        s=Match(6,2)
        aa=s.sub()
        self.assertEqual(aa,4)
        print("case 1 test_sub")
    def test_sub2(self):
        s=Match(1,3)
        aa=s.sub()
        self.assertEqual(aa,-2)
        print("case 2 test_sub2")

if __name__=="__main__":
    #unittest.main()
    suit=unittest.TestSuite
    suit.addTest(TestMatchsub("test_sub"))
    suit.addTest(TestMatchsub("test_sub2"))
    runner=unittest.TextTestRunner()
    runner.run(suit)
test_all.py

import unittest

test_dir = "./"
dd=unittest.defaultTestLoader.discover(test_dir,pattern="*run.py")

if __name__=="__main__":
    runner = unittest.TextTestRunner()
    runner.run(dd)
求解决,这厢有礼了