摘要:
内置fixture @pytest.fixture 装饰器的形式来使用 capfd Capture, as text, output to file descriptors 1 and 2. capfdbinary Capture, as bytes, output to file descript 阅读全文
摘要:
选择运行哪个测试 命令行形式 运行测试在module pytest test_mod.py 运行测试在一个目录 pytest testing/ 运行测试通过关键字表达 pytest -k "MyClass and not method" 这将运行包含与给定字符串表达式(不区分大小写)匹配的名称的测试 阅读全文
摘要:
How to install and use plugins pip install pytest-NAME pip uninstall pytest-NAME some popular plugins pytest-django: write tests for django apps, usin 阅读全文
摘要:
安装pytest pip install -U pytest # -U就是 --upgrade,意思是如果已安装就升级到最新版 A sample def func(x): return x+1; def test_answer(): assert func(3) == 5 test 结果 test 阅读全文
摘要:
虚拟环境工具 安装poetry pip install -U peotry 上述方式不行时 (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python 加入环境变量 初始化项 阅读全文
摘要:
基本概念 test fixture 测试夹具 测试预先操作以及测试的后置操作 test case 测试用例 测试用例 unittes 提供一个基础类TestCase test suit 测试套 测试用例的集合容器,聚集要一起执行的用例 test runner 测试运行器 协调测试执行并向用户提供结果 阅读全文
摘要:
日志级别严重性 DEBUG:细节信息,仅当诊断问题的时候适用 INFO:确认程序按预期运行 WARNING:表明有已经或即将发生的意外。程序仍按预期进行。 ERROR:由于严重的问题,程序的某些功能已经不能正常执行 CRITICAL:严重的错误,表明程序已不能继续进行 import logging 阅读全文
摘要:
Example import pluggy hookspec = pluggy.HookspecMarker("myproject") # 创建hooksepc 注解 hookimpl = pluggy.HookimplMarker("myproject") # 创建hookimpl 注解 clas 阅读全文
摘要:
对python内建容器dict、list、set、tuple的补充 namedtuple 命名元组 deque 队列 ChainMap 类似字典的类,用于创建包含多个映射的单个视图 包含多个自典的类 Counter 计数hashable对象的字典子类 OrderedDict 有序字典 default 阅读全文
摘要:
按位逻辑运算 取反 ~ 一元运算符~把1变为0,把0变为1 ~(10011010) 01100101 val = ~val 按位与 & 二元运算符&通过逐位比较两个运算对象,生成一个新值。对于每个位,只有两个运算对象中相应的位都为1时,结果才为1 (10010011) & (00111101) (0 阅读全文