随笔分类 - Pytest
摘要:import os os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0]
阅读全文
摘要:在一台测试机器执行`pytest`命令时报错:`AttributeError: module 'pytest' has no attribute 'StashKey'`  def fixture1(request): print(requ
阅读全文
摘要:本地打开html文件显示正常是应为本地有css,而被人没有。我们打开浏览器查看F12,加载了本地路径中的css文件 : print('正
阅读全文
摘要:pytest 中fixture参数化到底什么时候使用? 背景 都知道我们可以把前置准备和后置处理放到fixture中,那么fixture参数化是用来干什么的? 官方教程 # content of conftest.py import pytest import smtplib @pytest.fix
阅读全文
摘要:背景 往往在测试过程中,数据是在自动化用例执行之后才生成的,并非一开始就知道,又想在用例结束的时候清理掉这些中间数据,该怎么办? 思路 之前解决的办法是使用cache来解决的: conftest.py: import pytest @pytest.fixture() def myfixture(ca
阅读全文
摘要:测试分为四个步骤: 1.Arrange 2.Act 3.Assert 4.Cleanup Arrange安排 是我们为考试做准备。 Act 启动 。这一行为实现了被测系统(SUT)状态的改变,也是我们可以查看的改变后的状态,以便我们对行为做出判断。这通常采用函数/方法调用的形式。 Assert 断言
阅读全文
摘要:pymysql.err.InterfaceError: (0, '') 背景 自动化代码需要坚固开发服和测试服,但是又有一些固定数据(或者说是死数据),无法同时满足开发服和测试服,每次if...else...判断url很烦,如果涉及到修改那就更麻烦了需要找到所有的if...else...。 解决办法
阅读全文
摘要:背景 前段时间一直认为loguru这个库很不错,并且应用到了项目中,生成的日志文件也非常好看但是最后的allure报告中和html报告中都没有log信息。 然就是各种查查: loguru作者说loguru默认是stderr ,然后了解啥是:stdout 和stderr学习地址:https://bbs
阅读全文
摘要:背景 最近紧急支持一个接口测试,打算把接口的参数都放到execl中维护,且一个接口需要请求两次。 使用技术 excel中写入要测试的用例,包含接口、传入的参数、请求预期结果、等级等 openpyxl读取excel @pytest.mark.parametrize('data', all_list)接
阅读全文
摘要:Pytest教程 Pytest框架中print的奇怪现象 test_02_01.py """ pytest 中print的使用 """ from assertpy import assert_that import pytest # fun1为我们测试的函数:传一个参数自动+1 def fun1(x
阅读全文
摘要:Pytest教程 安装pytest pip install pytest 创建一个以test开头的py文件(或者test结尾) pytest会自动寻找以test开头或者结尾的py,在当前路径下面 test_01.py # fun1为我们测试的函数:传一个参数自动+1 def fun1(x): """
阅读全文
摘要:今天看pytest官网无意间发现了这个好用的方法.无需修改自己的用例,自动计算 官网地址 conftest.py import pytest import time DATE_FORMAT = '%Y-%m-%d %H:%M:%S' @pytest.fixture(scope='session',
阅读全文
摘要:conftest.py import pytest @pytest.fixture() def test_1(): print('\n') print(' 前置 test1 ') @pytest.fixture() def test_2(): print(' 前置==test2 ') yield p
阅读全文
摘要:Pytest中使用assertpy断言 在我调研assertpy的时候发现了这么一句话: Of course, assertpy works best with a python test runner like pytest (our favorite) or Nose. 那么正好我们也是使用py
阅读全文
摘要:@pytest.mark.repeat(count)
阅读全文