python - 如何删除跳过测试的详细输出?
问题描述
背景:我有一堆测试(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)
解决方案
虽然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.
推荐阅读
- pandas - Pandas 确实基于字段进行汇总
- python - Jinja2 - 复制变量而不是引用它
- google-app-engine - 是否可以从另一个项目连接到 Google Cloud Memorystore?
- google-sheets - 如何在 Google 表格中选择正确的范围
- angular - 我的 vs 代码中的自动导入为 rxjs 运算符和 CanActivate 接口建议了模棱两可的导入语句
- python - 如何组合来自多个文件的多行并将它们放入数组
- django - 为什么 React 不显示任何数据?
- bash - 一个命令中 bash 中失败的反引号的默认值
- typescript - 在模块内使用模块进行类型声明无法编译(TS2503 找不到命名空间)
- javascript - 目标循环的html属性奇异