首页 > 解决方案 > 如何删除跳过测试的详细输出?

问题描述

背景:我有一堆测试(20+)我无法在我的工作机器上执行,因为它们需要一个工作的 CUDA 环境。所以为了避免错误,我通过unittest.skipIf.

抽象出细节,我的测试模块如下所示:

@unittest.skipIf(os.environ.get('TEST_FANCY') != 'yes', "For fancy tests, set TEST_FANCY='yes'")
class FancyTests(unittest.TestCase):
    def test_a(self):
        self.assertEqual(1+1, 2)

    def test_b(self):
        self.assertEqual(1+2, 3)

现在,当我运行测试时green,每个跳过的测试都会以冗长的方式报告,严重污染输出,例如:

..ss.

Skipped test.test_fancy.FancyTests.test_a - For fancy tests, set TEST_FANCY='yes'

Skipped test.test_fancy.FancyTests.test_b - For fancy tests, set TEST_FANCY='yes'

Ran 5 tests in 0.355s using 4 processes

OK (passes=3, skips=2)

我希望输出只是总结结果,类似于标准 unittest 运行器默认执行的操作,即:

..ss.

Ran 5 tests in 0.355s using 4 processes

OK (passes=3, skips=2)

标签: pythonpython-unittestpython-green

解决方案


虽然green默认报告单个跳过的测试,但它允许通过-k. 从文档

  -k, --no-skip-report  Don't print the report of skipped tests after testing
                        is done. Skips will still show up in the progress
                        report and summary count.

推荐阅读