D82【python 接口主动化学习】- pytest底子用法

[复制链接]
发表于 2025-12-17 01:45:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
day82 pytest初体验

学习日期:20241128
学习目标:pytest底子用法 -- pytest初体验
学习条记:
文件定名规范


  • py测试文件必须以test_开头(或_test末端)
  • 测试方法必须以test开头
  • 测试类必须以Test开头,而且不能有init方法
安装pytest-ordering包
  1. #1、登录 2、查找商品 3、下单 4、支付
  2. import pytest
  3. def testlogin():
  4.     print("login...")
  5. @pytest.mark.run(order=1)
  6. def test_search():
  7.     print("search...")
  8. def test_order():
  9.     print("order...")
  10. def testpay():
  11.     print("pay...")
复制代码
常用断言范例
  1. def test_assert():
  2.     assert 1 != 2
  3.     assert 1<2
  4.     assert 2>1
  5.     assert 1>=1
  6.     assert 1<=1
  7.     assert 'a' in 'abc'
  8.     assert 'a' not in 'bc'
  9.     assert True is True
复制代码
总结


  • py测试文件必须以test_开头(或_test末端)
  • 测试方法必须以test开头
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表