pytest 前后置方法

简介: pytest 前后置方法

代码

import pytest
class TestFrontBack:
    def setup_class(self):
        print("前置条件(作用域:每个类执行之前):创建日志对象,创建数据库连接")
    def setup(self):
        print("前置条件(作用域:每个用例执行之前):打开谷歌,窗口最大化")
    def test_login(self):
        print('点击登录')
        print('输入账号')
        print('输入密码')
        print('点击登录')
    def test_buy(self):
        print('登录界面输入账号密码')
        print('点击登录')
        print('查看商品加入购物车')
        print('购物车购买支付商品')
        print('查看账户余额')
    def teardown(self):
        print('后置条件(作用域:每个用例执行之前后):关闭谷歌')
    def teardown_class(self):
        print('后置条件(作用域:每个类执行之前后):销毁日志对象,销毁数据库连接')
if __name__ == '__main__':
    pytest.main([r'D:\python新代码集\pytest_study\basics\test_front_back.py'])

运行结果

目录
打赏
0
0
0
0
4
分享
相关文章
pytest Mark标记测试用例
使用`pytest.mark`进行测试用例分组和筛选,如`@pytest.mark.webtest`。通过`pytest -m`参数执行特定标记的用例,例如`pytest -s test_command_param.py -m webtest`。同时,pytest支持内置的skip、skipif和xfail功能来管理特殊用例:skip始终跳过,skipif条件满足时跳过,xfail则标记预期失败的测试。
Pytest前后置以及fixture实战部分
Pytest前后置以及fixture实战部分
64 0
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
212 0
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
128 0
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
pytest学习和使用19-pytest断言失败后,怎样保持后续的断言继续执行?(pytest-assume)
pytest学习和使用19-pytest断言失败后,怎样保持后续的断言继续执行?(pytest-assume)
198 0
下一篇
oss创建bucket
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等