0


vscode上对python进行单元测试

1 在settings.json中添加如下

"python.testing.unittestArgs": [
        "-v",
        "-s",
        "./",
        "-p",
        "*_test.py"
    ],
    "python.testing.pytestEnabled": false,
    "python.testing.unittestEnabled": true,

-s后的参数代表启动路径

-p 代表测试文件pattern

2 创建测试文件

as_test.py

注意函数名要以'test_'开头

import unittest
class TestStringMethods(unittest.TestCase):
    def test_add(self):
        a = 1
        b = 2
        self.assertEqual(a,1)
    def test_upper(self):
        # self.assertEqual('foo'.upper(), 'FOO')
        print("here")
        print("dasdasdwadawdwad")

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split fails when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)

if __name__ == '__main__':
    unittest.main()
标签: python vscode

本文转载自: https://blog.csdn.net/Woody453253/article/details/129851006
版权归原作者 湖魂 所有, 如有侵权,请联系我们删除。

“vscode上对python进行单元测试”的评论:

还没有评论