跳转到主要内容

单元测试运行程序,生成测试任何协议(TAP)输出

项目描述

simpletap 是一个测试运行程序,它集成与unittest框架,以产生兼容 TAP (Test Anything Protocol) 的输出。

https://github.com/unode/simpletap/actions/workflows/main.yml/badge.svg

用法

在您的测试脚本中,而不是

if __name__ == "__main__":
    unittest.main()

使用

if __name__ == "__main__":
    from simpletap import TAPTestRunner
    unittest.main(testRunner=TAPTestRunner(buffer=True))

一个小测试案例,如

import unittest

class IntegerArithmeticTestCase(unittest.TestCase):
    def testAdd(self):  # test method names begin 'test*'
        "test adding values"
        self.assertEqual((1 + 2), 3)
        self.assertEqual(0 + 1, 1)

    def testMultiply(self):
        "test multiplying values"
        self.assertEqual((0 * 10), 0)
        self.assertEqual((5 * 8), 40)

    def testFail(self):
        "a failing test"
        self.assertEqual(0, 1)

    @unittest.expectedFailure
    def testExpectFail(self):
        "we saw this coming"
        self.assertEqual(0, 1)

    @unittest.expectedFailure
    def testUnexpectFail(self):
        "someone fixed it already"
        self.assertEqual(0, 0)

    @unittest.skipIf(True, "Skipping this one")
    def testSkip(self):
        "pending a fix"
        self.assertEqual(0, 1)

    def testError(self):
        "oops something went wrong"
        no_such_variable + 1  # Oops!

if __name__ == "__main__":
    from simpletap import TAPTestRunner
    unittest.main(testRunner=TAPTestRunner(buffer=True))

当保存到名为 test.py 的文件中并执行时,会产生

1..7
ok 1 - test.py: test adding values
not ok 2 - test.py: oops something went wrong
# ERROR: NameError on file test.py line 38 in testError: 'no_such_variable + 1  # Oops!':
#        name 'no_such_variable' is not defined
ok 3 - test.py: we saw this coming # TODO
# EXPECTED_FAILURE: AssertionError on file test.py line 24 in testExpectFail: 'self.assertEqual(0, 1)':
#                   0 != 1
not ok 4 - test.py: a failing test
# FAIL: AssertionError on file test.py line 19 in testFail: 'self.assertEqual(0, 1)':
#       0 != 1
ok 5 - test.py: test multiplying values
ok 6 - test.py: pending a fix # skip
# SKIP:
#       Skipping this one
not ok 7 - test.py: someone fixed it already # FIXED
# UNEXPECTED_SUCCESS:
#                     testUnexpectFail (__main__.IntegerArithmeticTestCase)

您也可以直接从命令行启动 simpletap,方式与unittest相同

python -m simpletap test.IntegerArithmeticTestCase

测试

测试套件配置为通过 tox 运行。

项目

simpletap 目前正在被以下项目使用

更改日志

2.0.0

  • skip 关键字不再使用。现在完全符合 TAP 使用 ok/not ok

  • SKIP 现在导致 ok

  • EXPECTED_FAILURE 现在导致 ok

  • UNEXPECTED_SUCCESS 现在被明确处理并导致 not ok

项目详情


下载文件

下载适用于您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

simpletap-2.0.0.tar.gz (11.6 kB 查看哈希值)

上传时间

构建分布

simpletap-2.0.0-py3-none-any.whl (12.6 kB 查看哈希值)

上传时间 Python 3

由以下提供支持