将unittest测试用例转换为pytest
unittest2pytest的Python项目详细描述
Author: | Hartmut Goebel <h.goebel@crazy-compilers.com> |
---|---|
Version: | 0.4 |
Copyright: | 2015-2019 by Hartmut Goebel |
Licence: | GNU Public Licence v3 or later (GPLv3+) |
Homepage: | https://github.com/pytest-dev/unittest2pytest |
unittest2pytest是一个帮助重写python的工具。 将测试用例转换成pytest测试用例。
与其他类似的工具相比,这个unittest2pytest
- 处理关键字参数,
- 在一条线上处理单行测试用例和多个测试,
- 在适当的地方使用上下文处理程序。
这是通过使用lib2to3和python强大的^{tt2}完成的。$ 模块。
安装
要安装unittest2pytest,只需运行:
pip install unittest2pytest
用法
打印UnitTest2ByTest将对 特定源文件或目录:
unittest2pytest source_folder
要将这些更改写入文件:
unittest2pytest -w source_folder
将这些更改写入另一个目录:
unittest2pytest -w source_folder --output-dir /some/where/else
默认情况下,这将为 改变。您可以添加-n选项以不创建备份。拜托 如果不使用版本控制系统,请不要执行此操作。
有关运行特定修复程序的更多选项,请运行 unittest2pytest --help或读取lib2to3 documentation。这个 工具建在那个上面。
修复
可用修复程序的列表如下:
$ unittest2pytest -l Available transformations for the -f/--fix option: remove_class self_assert
注意:如果您的测试使用上下文管理器with self.assertRaises或 with self.assertWarns,它们将转换为pytest.raises或 pytest.warns合适,但是由于语义不同,任何 使用上下文管理器的输出值(例如 with pytest.raises(ValueError) as x:)将是错误的,需要 事后手动调整。
更改日志
0.4(2019-06-30)
- 添加对assertDictContainsSubset的支持。
- 如果需要,请在表达式周围加上括号。
- 修复了AssertRaiseResRegex、AssertRaiseResRegexp和AssertWarnsRegex。 正则表达式被一个未定义的变量模式取代。
- 用**kwargs和 原子参数。
- 使用AssertRaiseResRegex、AssertRaiseResRegexp和AssertWarnsRegex pytest中的matchkwarg将引发而不是创建变量 使用上下文管理器并在re.search上执行断言。
- 添加简短的开发人员指南。
- 删除python 3.0、3.1、3.2、add3.6和3.7上的测试。
- 将包装作为万向轮分发。
v0.3(2016-07-26)
- 添加对assertraises/assertwarns上下文管理器的支持。
- 添加对将assertraises中的lambda参数转换为 上下文管理器。
- 修复一些不正确的转换。
- 内部清理和修复。
V0.2(2015-10-20)
- 添加对assertregex/assertregexpmatches、assertnotregex的支持, assertraisesregex/assertraisesregexp,assertwarnsregex公司。
- unittest2pytest现在是一个子项目。
- 小修小修。
v0.1(2015-10-16)
- 初始版本