摘要: 指定测试用例失败N次后停止测试 pytest --maxfail=n 指定测试用例测试 对模块文件测试 pytest test.py对指定模块中测试用例进行测试pytest test.py::test_one对指定文件夹进行测试pytest test/对指定标记符修饰的测试用例进行测试pytest 阅读全文
posted @ 2021-10-10 17:18 湫梨花颂歌 阅读(142) 评论(0) 推荐(0)
摘要: 测试类与测试函数的命名 我自己习惯为测试类:TestClassName,测试函数test_funcname class TestUtils(object): def test_add(self): assert 1+1 == 2 def test_minus(self): assert 1-2 == 阅读全文
posted @ 2021-10-10 15:33 湫梨花颂歌 阅读(99) 评论(0) 推荐(0)
摘要: def raises( expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], *args: Any, **kwargs: Any ) -> Union["RaisesContext[_E]", _pytest._code.Excepti 阅读全文
posted @ 2021-10-10 15:08 湫梨花颂歌 阅读(206) 评论(0) 推荐(0)
摘要: with语句的使用可以简化try...except...finally语句 当我们之前从磁盘上读取某个文件时,会使用try...except...finally语句,这样虽然解决了当文件未找到时,程序会捕获异常,并不会突然退出,并打印我们自己定义的错误信息,但是这样的写法未必过于冗余 try: fi 阅读全文
posted @ 2021-10-08 22:08 湫梨花颂歌 阅读(347) 评论(0) 推荐(0)