代码拉取完成,页面将自动刷新
unittest subTest()
support and subtests
fixture.
This pytest plugin was generated with Cookiecutter along with @hackebrot's cookiecutter-pytest-plugin template.
subtests
fixture, providing similar functionality for pure pytest tests.You can install pytest-subtests
via pip from PyPI:
$ pip install pytest-subtests
import unittest
class T(unittest.TestCase):
def test_foo(self):
for i in range(5):
with self.subTest("custom message", i=i):
self.assertEqual(i % 2, 0)
if __name__ == "__main__":
unittest.main()
Output
λ pytest .tmp\test-unit-subtest.py ======================== test session starts ======================== ... collected 1 item .tmp\test-unit-subtest.py FF. [100%] ============================= FAILURES ============================== _________________ T.test_foo [custom message] (i=1) _________________ self = <test-unit-subtest.T testMethod=test_foo> def test_foo(self): for i in range(5): with self.subTest('custom message', i=i): > self.assertEqual(i % 2, 0) E AssertionError: 1 != 0 .tmp\test-unit-subtest.py:9: AssertionError _________________ T.test_foo [custom message] (i=3) _________________ self = <test-unit-subtest.T testMethod=test_foo> def test_foo(self): for i in range(5): with self.subTest('custom message', i=i): > self.assertEqual(i % 2, 0) E AssertionError: 1 != 0 .tmp\test-unit-subtest.py:9: AssertionError ================ 2 failed, 1 passed in 0.07 seconds =================
subtests
fixture example
def test(subtests):
for i in range(5):
with subtests.test(msg="custom message", i=i):
assert i % 2 == 0
Output
λ pytest .tmp\test-subtest.py ======================== test session starts ======================== ... collected 1 item .tmp\test-subtest.py .F.F.. [100%] ============================= FAILURES ============================== ____________________ test [custom message] (i=1) ____________________ def test(subtests): for i in range(5): with subtests.test(msg='custom message', i=i): > assert i % 2 == 0 E assert (1 % 2) == 0 .tmp\test-subtest.py:4: AssertionError ____________________ test [custom message] (i=3) ____________________ def test(subtests): for i in range(5): with subtests.test(msg='custom message', i=i): > assert i % 2 == 0 E assert (3 % 2) == 0 .tmp\test-subtest.py:4: AssertionError ================ 2 failed, 1 passed in 0.07 seconds =================
Contributions are very welcome. Tests can be run with tox:
tox -e py37
Distributed under the terms of the MIT license, "pytest-subtests" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。