【问题标题】:Load specific test via TestLoader通过 TestLoader 加载特定的测试
【发布时间】:2017-01-04 09:27:48
【问题描述】:

我正在使用 python 单元测试,并希望通过指定其路径来加载(并运行)特定测试。

我正在寻找这样的东西: unitTest.TestLoader().Load('path_to_test')

(需要进一步解析)

任何关于如何实现这一目标的建议都将不胜感激。 谢谢

【问题讨论】:

    标签: python python-2.7 unit-testing python-unittest


    【解决方案1】:

    我最终得到了一个简单的解析器来将/ 转换为.(在路径中)以加载特定的测试。像这样的:

            splitted_path = path.split("/")
    
            test_dir = '/'.join(splitted_path[:-1])
            test_name = splitted_path[-1]
            if not test_name.startswith('test'):
                raise RuntimeError(
                    'Test name ({}) does NOT start with "test"'.format(
                        test_name))
            tests = unittest.TestLoader().discover(
                test_dir, pattern=test_name)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-31
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多