There was an error while loading. Please reload this page.
测试框架: pytest
持续集成服务: travis ci
代码覆盖率计算: codecov
安装pytest。在Python3.6环境下 pip install pytest 或者 conda install pytest。通过pytest --version 确认该pytest对应Python 3.6。
原理:在任意文件目录命令行运行pytest, 会自动寻找所有文件名以test为前缀或后缀的文件。在每个这样的文件中,自动执行以test_开头的函数,函数体内可以通过Assert等语句检查运行结果。(参考资料:https://docs.pytest.org/en/latest/getting-started.html# 据观察,pytest也能找到unittest的测试,unittest是另一套测试框架。)
测试的过程是:
class Foo(object): def __init__(self, val): self.val = val def __eq__(self, other): return self.val == other.val def test_compare(): f1 = Foo(1) f2 = Foo(2) assert f1 == f2
更多测试例子,参考https://docs.pytest.org/en/latest/assert.html#assert