![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pytest
文章平均质量分 50
词穷墨尽
don't try so hard the best things come when you least expect them to
不定时更新~~
展开
-
pytest 失败截图
@pytest.hookimpl(tryfirst=True, hookwrapper=True)def pytest_runtest_makereport(item, call): outcome = yield rep = outcome.get_result() if rep.when == 'call' and rep.outcome == "failed": driver = getattr(Context, "driver") logg.原创 2022-11-15 10:03:53 · 422 阅读 · 0 评论 -
pytest_runtest_protocol
pytest_runtest_protocol获取 当前执行用例 以及下一个用例,内容待完善原创 2022-03-08 17:32:50 · 353 阅读 · 0 评论 -
pytest fixture 当刷scope=class时 类中多个测试方法 返回对象不一致问题
class Test111: @pytest.fixture(scope="class", autouse=True) def get_service(self, session, logger): self.service = EvaluationTeacherService(session, logger) return self.service def test_edit_evaluation(self): print(id(.原创 2021-05-27 15:00:49 · 497 阅读 · 0 评论 -
pytest pycharm 运行 生成 allure 报告
import pytestimport allurefrom service.item_bank.label.source.source_service import SourceServiceimport os@allure.feature('随机获取来源下拉框')class TestGetsourceCase: """难度下拉框""" @allure.feature('随机获取来源下拉框') def test_get_region(self,get_url,.原创 2021-01-11 10:11:10 · 1311 阅读 · 0 评论 -
pytest hook方法总结
钩子函数总结第一部分:setuptools引导挂钩要求足够早注册的插件(内部和setuptools插件),可以使用的钩子pytest_load_initial_conftests(early_config,parser,args): 在命令行选项解析之前实现初始conftest文件的加载。 pytest_cmdline_preparse(config,args): (不建议使用)在选项解析之前修改命令行参数。 pytest_cmdline_parse(pluginmanager,args):转载 2021-01-06 17:02:20 · 1646 阅读 · 0 评论 -
pytesfixture 使用 pytest.mark.parametrize参数化的数据
原创 2020-09-16 15:41:44 · 225 阅读 · 0 评论 -
pytest 一旦失败跳过后面的测试(官网看的)
from typing import Dict, Tupleimport pytest# store history of failures per test class name and per index in parametrize (if parametrize used)_test_failed_incremental: Dict[str, Dict[Tuple[int, ...], str]] = {}def pytest_runtest_makereport(item, ca..转载 2020-09-08 11:18:27 · 1154 阅读 · 0 评论 -
pytest_addoption 动态添加命令行参数并获取,与 自定义跳过某些标记的测试(pytest_collection_modifyitems)
conftest.pydef pytest_configure(config): config.addinivalue_line("markers", "slow: mark test as slow to run") config.addinivalue_line("markers", "victor: mark test as slow to run") # 与pytest.ini 中一样就是注册一下但是仍可以使用未定义的标记def pytest_addoption(par.原创 2020-09-07 15:35:09 · 1948 阅读 · 4 评论 -
pytest capfdbinary,capys捕获异常
"""如果被测代码写入非文本数据,则可以使用capsysbinary固定装置捕获该数据,而不是bytes从readouterr方法返回。如果被测代码写入非文本数据,则可以使用capfdbinary固定装置捕获该数据,而不是bytes从readouterr方法返回。该capfdbinary夹具上的文件描述符级别运行。"""def test_myoutput(capfdbinary): # or use "capfd" for fd-level print("hello") .原创 2020-09-07 11:22:02 · 431 阅读 · 0 评论 -
pytest 内置 fixtures 之 cache:使用 cache 写入、读取 pytest 缓存
#!/usr/bin/python# -*- coding: UTF-8 -*-# @Time : 2020/8/31 11:29# @Author : victor# @Email : import pytestimport timefrom _pytest.fixtures import SubRequestdef expensive_computation(): print("running expensive computation....原创 2020-09-02 17:45:15 · 569 阅读 · 0 评论 -
pytest 一些常用插件
用例失败后自动重新运行:pytest-rerunfailures,使用方法: 安装插件:pip install pytest-rerunfailures pytest test_x.py --reruns=n (失败后重运行的次数) 重复运行测试:pytest-repeat,使用方法: 安装插件:pip installpytest-repeat pytest test_x.py --count=n (重复运行的次数) 多线程执行测试任务:pytest-xdist,使用方法: 安装.原创 2020-09-02 16:30:56 · 756 阅读 · 0 评论 -
pytest批量执行
import pytestimport ospath = os.path.dirname(__file__)path = path + "/report/"pytest.main(["-s","--alluredir={}".format(path), "cases"])#运行 cases下所有测试用例result = os.system(r"allure serve {}".format(path))print("result={}".format(result).原创 2020-08-31 11:16:46 · 2106 阅读 · 0 评论 -
pytest conftest 获取case中的变量
smtpserver="www.baidu.com"#case中有该变量确保能获取到@pytest.fixture(scope="session")# @contextlib.contextmanagerdef connect(): # raise RuntimeError("12312") print("yield 之前") yield Foo(1, 2) ... # close connection print("yield 之后")def tes.原创 2020-08-13 16:06:23 · 1253 阅读 · 0 评论 -
使用functools.partial 绑定函数/预设参数值
def sub(x, y): return x - y def attach_wrap(func1, func2=None): if func2 is None: return functools.partial(attach_wrap, func1)#返回attach_warp(sub,*args,*kwargs) setattr(func1, func2.__name__, func2) retu...原创 2020-08-13 15:31:01 · 305 阅读 · 0 评论 -
pytest夹具完成/执行拆卸代码
@contextlib.contextmanagerdef connect(port): print("yield 之前") yield Foo(1,2) ... # close connection print("yield 之后")@pytest.fixturedef equipments(request): r = [] for port in ("C1", "C3", "C28"): cm = connect(port).原创 2020-08-13 14:44:53 · 201 阅读 · 0 评论 -
pytest 间接参数化
原创 2020-08-12 16:33:11 · 118 阅读 · 0 评论 -
pytest_assertrepr_compare 自定义失败的断言解释
test_login.pyconftest.py原创 2020-08-12 14:54:51 · 742 阅读 · 0 评论