pytest简明教程

1. 简介

pytest是一款基于Python的测试框架。与Python自带的unittest相比,pytes语法更加简洁,断言更加强大,并且在自动测试以及插件生态上比unittest都要更加强大。

1.1. 安装pytest

pip install pytest

1.2. pytest命名规则

pytest默认会自动搜索当前目录中符合规则的源文件,并在源文件中搜索符合规则的类、函数来执行测试。

  1. 用例源文件:以test_开头或以_test结尾的.py源文件。

  2. 用例类:以Test开头的类名。

  3. 用例函数:以test开头的函数名。

2. 基本功能

2.1. 函数测试

2.1.1. 单函数测试

示例代码

    # coding=utf-8def test_addition():result = 2 + 2assert result == 4

执行测试

    J:\2023\9\Python>pytest=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0rootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 1 itemtest_main.py .                                                        [100%]============================ 1 passed in 0.02s =============================

2.1.2. 多函数测试

示例代码

    # coding=utf-8# test_main.py def test_addition():result = 2 + 2assert result == 4def test_subtraction():result = 5 - 3assert result == 3

执行测试1

有一个测试用例错误,会指出详细的错误提示信息。

    J:\2023\9\Python>pytest=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0rootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 2 itemstest_main.py .F                                                       [100%]================================= FAILURES =================================_____________________________ test_subtraction _____________________________def test_subtraction():result = 5 - 3>       assert result == 3E       assert 2 == 3test_main.py:9: AssertionError========================= short test summary info ==========================FAILED test_main.py::test_subtraction - assert 2 == 3======================= 1 failed, 1 passed in 0.46s ========================

执行测试2

测试指定文件,pytest默认会测试当前目录中所有满足要求的文件。如果只想测试其中1个,可以指定测试文件。

    J:\2023\9\Python>pytest test_main.py=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0rootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 2 itemstest_main.py .F                                                       [100%]================================= FAILURES =================================_____________________________ test_subtraction _____________________________def test_subtraction():result = 5 - 3>       assert result == 3E       assert 2 == 3test_main.py:9: AssertionError========================= short test summary info ==========================FAILED test_main.py::test_subtraction - assert 2 == 3======================= 1 failed, 1 passed in 0.43s ========================

2.1.3. 测试指定函数

示例代码

    # coding=utf-8# test_main.py def test_addition():result = 2 + 2assert result == 4def test_subtraction():result = 5 - 3assert result == 3

执行测试

有时只想测试一个指定函数,可指定测试函数名。

    J:\2023\9\Python>pytest test_main.py::test_addition=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0rootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 2 items / 1 deselected / 1 selectedtest_main.py .                                                        [100%]===================== 1 passed, 1 deselected in 0.02s ======================

2.2. 类测试

示例代码

    # coding=utf-8# test_main.pyclass TestExample:def test_addition(self):assert 2 + 2 == 4def test_subtraction(self):assert 5 - 3 == 2def test_multiplication(self):assert 3 * 4 == 12

执行测试

  1. 默认测试当前目录下所有满足要求的文件中的所有满足要求的测试类以及测试函数:pytest

  2. 指定测试文件:pytest test_main.py

  3. 指定指定文件的测试类: pytest test_main.py::TestExample

  4. 测试指定类:pytest -k “TestExample”

  5. 测试指定文件指定类的指定函数:pytest test_main.py::TestExample::test_subtraction

    J:\2023\9\Python>pytest test_main.py::TestExample::test_subtraction=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0rootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 1 itemtest_main.py .                                                        [100%]============================ 1 passed in 0.03s =============================

2.3. 测试参数

2.3.1. 基本用法

在 pytest 中,有一些常用的测试参数可以帮助你更好地控制和定制测试的行为。以下是几个常用的 pytest 测试参数:

  1. -k EXPRESSION: 通过关键字表达式选择要运行的测试用例。例如,-k “test_func” 将只运行名称中包含 “test_func” 的测试函数。

  2. -s: 允许在测试运行期间输出打印语句和日志信息。这对于调试测试时非常有用。

  3. -v: 输出详细的测试结果信息,包括每个测试函数的名称和执行状态。

  4. -x: 遇到第一个测试失败或错误后立即停止测试运行。

  5. –maxfail=num: 在运行多个测试函数时,最多允许 num 个失败。超过这个限制后,测试将被中断。

  6. –tb=style: 设置回溯(traceback)显示风格。可以选择的选项包括 auto(默认)、short、line、no 和 native。

  7. –cov=PACKAGE: 测试代码覆盖率报告的命令行选项。可以指定要计算覆盖率的包或模块。

  8. -m: 通过在测试用例上添加装饰器 @pytest.mark. ,你可以给测试用例打上标记。然后,使用 -m 选项来指定标记名称,从而过滤特定的测试用例进行运行。

这只是 pytest 中一部分常用测试参数的示例。你可以通过运行 pytest --help 命令获取完整的测试参数列表,并查阅 pytest 官方文档以了解更多详细信息和用法。

示例代码

    # coding=utf-8# test_main.pyclass TestExample:def test_addition(self):assert 2 + 2 == 4def test_subtraction(self):assert 5 - 3 == 2def test_multiplication(self):assert 3 * 4 == 12

执行测试

    J:\2023\9\Python>pytest -v -s test_main.py::TestExample=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 3 itemstest_main.py::TestExample::test_addition PASSEDtest_main.py::TestExample::test_subtraction PASSEDtest_main.py::TestExample::test_multiplication PASSED============================ 3 passed in 0.03s =============================

2.3.2. 代码用法

在命令行中指定参数,更灵活,但是每次都输入,也麻烦。

pytest有提供pytest.main函数,将命令行参数全部移到此函数的参数列表中。

示例代码

    # coding=utf-8    # test_main.pyimport pytestclass TestExample:def test_addition(self):assert 2 + 2 == 4def test_subtraction(self):assert 5 - 3 == 2def test_multiplication(self):assert 3 * 4 == 12if __name__ == '__main__':pytest.main(['-s', '-v', 'test_main.py'])

执行代码

    J:\2023\9\Python>python test_main.py=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 3 itemstest_main.py::TestExample::test_addition PASSEDtest_main.py::TestExample::test_subtraction PASSEDtest_main.py::TestExample::test_multiplication PASSED============================ 3 passed in 0.03s =============================

3. 高级功能

3.1. 参数化

测试的时候经常会遇到单个函数测试不同的参数,如果每种参数单独写一个测试函数,会重复麻烦。有没有更简单的方法?参数化测试就是解决此问题的。

在 pytest 中,参数化(Parameterization)是一种强大的功能,允许你在单个测试函数中运行多次相同或类似的测试用例。这样可以减少重复的代码,并使测试更加简洁和可读。

示例代码

主要是通过给测试函数添加pytest.mark.parametrize的装饰器来实现

    # coding=utf-8    # test_main.pyimport pytest# 定义被测试的函数def add(a, b):return a + b# 使用参数化装饰器定义参数化测试@pytest.mark.parametrize("a, b, expected_result", [(1, 2, 3),  # 第一个测试用例,a=1, b=2, 预期结果为 3(5, 5, 10),  # 第二个测试用例,a=5, b=5, 预期结果为 10(-1, 0, -1)  # 第三个测试用例,a=-1, b=0, 预期结果为 -1])def test_add(a, b, expected_result):assert add(a, b) == expected_result

执行测试

    J:\2023\9\Python>pytest -v=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 3 itemstest_main.py::test_add[1-2-3] PASSED                                  [ 33%]test_main.py::test_add[5-5-10] PASSED                                 [ 66%]test_main.py::test_add[-1-0--1] PASSED                                [100%]============================ 3 passed in 0.03s =============================

@pytest.mark模块还有其他功能,如指定函数执行次数,指定测试条件,指定测试顺序、跳过指定测试等。

3.2. fixture

在软件测试中,“fixture” 一词通常被翻译为 “夹具”。 Fixture 是一个用于提供测试环境和共享资源的机制,在测试执行过程中设置和清理测试代码所需的条件。pytest.fixture也是一个装饰器,装饰器可以附加在指定函数上,来实现在函数调用前或调用后来执行额外的操作。

测试一般分4个阶段:Setup-Exercise-Verify-Teardown。(来自《xUnit Test Patterns 》)

fixture就负责实现Setup和Teardown部分。

3.2.1 用作输入

示例代码

在执行test_multiply时,调用fixture的形参input_values会优先执行,相当于setup。形参可以调用多个fixture参数,让参数输入测试更加灵活。

    import pytest# 定义一个简单的 Fixture,用于提供测试数据@pytest.fixturedef input_values():a = 5b = 10return a, b# 定义要测试的函数def multiply(a, b):return a * b# 使用 Fixture 进行测试def test_multiply(input_values):a, b = input_valuesresult = multiply(a, b)assert result == 50

执行测试

    J:\2023\9\Python>pytest -v=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 1 itemtest_main.py::test_multiply PASSED                                    [100%]============================ 1 passed in 0.03s =============================

3.2.2. Setup&Teardown

例如一个测试,每次开始测试前要连接数据库,测试完了之后要关闭数据库。如果每个测试用例中都添加一个connect_db和close_db函数,会显得有些重复。利用fixture的Setup&Teardown功能,就可以自动完成连接和关闭数据库。pytest.fixture提供了yield协程来实现此功能。

示例代码

    # coding=utf-8    # test_main.pyimport pytest@pytest.fixture()def db():print('\nConnection successful')yieldprint('\nConnection closed')def search_user(user_id):d = {'001': 'xiaoming'}return d[user_id]def test_search(db):assert search_user('001') == 'xiaoming'

执行测试

    J:\2023\9\Python>pytest -v -s=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 1 itemtest_main.py::test_searchConnection successfulPASSEDConnection closed============================ 1 passed in 0.03s =============================

3.2.3. 作用域

fixture有4种作用域,不同作用域有着不同的先后顺序,默认为函数级。

  • function: 函数级,每个测试函数都会执行一次固件;

  • class: 类级别,每个测试类执行一次,所有方法都可以使用;

  • module: 模块级,每个模块执行一次,模块内函数和方法都可使用;

  • session: 会话级,一次测试只执行一次,所有被找到的函数和方法都可用。

示例代码:

    # coding=utf-8    # test_main.pyimport pytest@pytest.fixture(scope='function')def func_scope():print("setup function")yieldprint("\nteardown function")@pytest.fixture(scope='module')def mod_scope():print("setup module")yieldprint("teardown module")@pytest.fixture(scope='session')def sess_scope():print("\nsetup session")yieldprint("teardown session")@pytest.fixture(scope='class')def class_scope():print("setup class")yieldprint("teardown class")def test_multi_scope(sess_scope, mod_scope, class_scope, func_scope):pass

执行测试

通过结果测试可以验证相关执行顺序

    J:\2023\9\Python>pytest -v -s=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 1 itemtest_main.py::test_multi_scopesetup sessionsetup modulesetup classsetup functionPASSEDteardown functionteardown classteardown moduleteardown session============================ 1 passed in 0.03s =============================

3.2.4. 自动执行

如果测试的每个函数都需要添加fixture参数来实现相关功能,会有些重复。autouse参数可以自动实现为所有作用域的函数、类、模块和会话添加Setup和Teardown功能。

示例代码

    # coding=utf-8    # test_main.pyimport pytest@pytest.fixture(scope='function', autouse=True)def func_scope():print("\nsetup function")yieldprint("\nteardown function")def test_multi_scope():pass

执行结果

    J:\2023\9\Python>pytest -v -s=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cacherootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 1 itemtest_main.py::test_multi_scopesetup functionPASSEDteardown function============================ 1 passed in 0.03s =============================

4. 其他

4.1. 插件化

pytest 是一个高度可扩展和插件化的测试框架。它提供了广泛的插件机制,使得用户可以根据需要添加、自定义或扩展各种功能。

以下是 pytest 插件化的一些关键特性:

  1. 自动发现和加载插件:pytest 能够自动发现并加载安装在项目中的插件。只需将插件包安装到项目环境中,pytest 就会自动识别并应用这些插件。

  2. 丰富的内置插件:pytest 内置了许多常用的插件,例如 capture 输出捕获插件、assertion 断言插件、coverage 代码覆盖插件等。这些内置插件提供了额外的功能和增强 pytest 的能力。

  3. 外部插件支持:除了内置插件,pytest 还支持第三方开发的插件。用户可以从社区中选择并使用各种插件,例如数据库插件、测试报告生成插件、测试数据生成插件等。

  4. 插件钩子函数:pytest 提供了一组钩子函数,允许插件介入测试执行过程中的不同阶段。通过实现这些钩子函数,插件可以在测试运行过程中进行自定义操作,如修改配置、收集测试用例、修改测试结果等。

  5. 自定义插件开发:如果现有的插件不能满足需求,用户还可以根据自己的需求开发定制化的插件。pytest 提供了丰富的 API 和文档,帮助用户编写自己的插件,并与其他 pytest 插件进行协作。

通过插件化的特性,pytest 提供了灵活、可定制的测试框架环境,使用户能够根据具体需求轻松扩展和定制 pytest 的功能,并集成额外的工具和服务。这使得 pytest 成为一个受欢迎的测试框架,适用于各种测试场景和项目规模。

4.2. 测试报告

pytest-html是常用的测试报告生成pytest插件。

4.2.1. 安装pytest-html

pip install pytest-html

4.2.2. 使用

    J:\2023\9\Python>pytest -sv --html=report.html=========================== test session starts ============================platform win32 -- Python 3.11.0, pytest-7.1.3, pluggy-1.0.0 -- C:\Users\Michael\AppData\Local\Programs\Python\Python311\python.execachedir: .pytest_cachemetadata: {'Python': '3.11.0', 'Platform': 'Windows-10-10.0.18363-SP0', 'Packages': {'pytest': '7.1.3', 'pluggy': '1.0.0'}, 'Plugins': {'anyio': '3.6.2', 'asyncio': '0.19.0', 'cov': '4.0.0', 'excel': '1.5.0', 'html': '4.0.2', 'metadata': '3.0.0', 'timeout': '2.1.0'}}rootdir: J:\2023\9\Pythonplugins: anyio-3.6.2, asyncio-0.19.0, cov-4.0.0, excel-1.5.0, html-4.0.2, metadata-3.0.0, timeout-2.1.0asyncio: mode=Mode.STRICTcollected 3 itemstest_main.py::TestExample::test_addition PASSEDtest_main.py::TestExample::test_subtraction PASSEDtest_main.py::TestExample::test_multiplication PASSED------- Generated html report: file:///J:/2023/9/Python/report.html --------============================ 3 passed in 0.25s =============================

4.2.3. 报告

image

4.3. 集成

  1. pytest可以方便地集成到Jenkins,并且可以用 Pytest+Allure生成更加可视的报告。

  2. pytest可以自动集成到vscode中,可以更加方便地手动执行单个或多个测试。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/139729.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

【MATLAB第77期】基于MATLAB代理模型算法的降维/特征排序/数据处理回归/分类问题MATLAB代码实现【更新中】

【MATLAB第77期】基于MATLAB代理模型算法的降维/特征排序/数据处理回归/分类问题MATLAB代码实现 本文介绍基于libsvm代理模型算法的特征排序方法合集,包括: 1.sing 2.adaboost 3.corr 4.svmrfe_ker 5.svmrfe_ori 1.sing 十折交叉取平均错误率值 累计贡…

UOS Deepin Linux 安装 anaconda

UOS Deepin Linux 安装 anaconda 下载 anaconda 官网下载 国内开源镜像站下载 官网下载 anaconda 官网: https://www.anaconda.com/ 点击右上角 Free Download 按钮 跳转值下载页面:https://www.anaconda.com/download 国内开源镜像站下载 清华大学开源…

【C++】STL详解(七)—— stack和queue的使用及模拟实现

​ ​📝个人主页:Sherry的成长之路 🏠学习社区:Sherry的成长之路(个人社区) 📖专栏链接:C学习 🎯长路漫漫浩浩,万事皆有期待 上一篇博客:【C】STL…

跨域问题解决方案(三种)

Same Origin Policy同源策略(SOP) 具有相同的Origin,也即是拥有相同的协议、主机地址以及端口。一旦这三项数据中有一项不同,那么该资源就将被认为是从不同的Origin得来的,进而不被允许访问。 Cross-origin resource…

strtok()函数的使用方法

strtok() 函数用于将字符串分割成子字符串&#xff08;标记&#xff09;。它在 C 语言中非常常用&#xff0c;可以通过指定分隔符来拆分原始字符串&#xff0c;并依次返回每个子字符串。 以下是 strtok() 函数的使用方法&#xff1a; #include <stdio.h> #include <…

JUC第七讲:关键字final详解

JUC第七讲&#xff1a;关键字final详解 final 关键字看上去简单&#xff0c;但是真正深入理解的人可以说少之又少。本文是JUC第七讲&#xff1a;关键字final详解&#xff0c;将常规的用法简化&#xff0c;提出一些用法和深入的思考。 文章目录 JUC第七讲&#xff1a;关键字fina…

光伏发电系统最大功率跟踪控制MATLAB仿真模型(电导增量法+扰动观察法)

微❤关注“电气仔推送”获得资料&#xff08;专享优惠&#xff09; 模型介绍&#xff1a; 模型主要包含光伏电池模块、直流升压模块、以及最大功率跟踪控制模块。 扰动观察法&#xff08; P&O &#xff09;&#xff1a; 所谓 P&O 就是每过一会给予系统工作电压一个可…

【C++】C++11——可变参数模板和emplace

可变参数模板的定义方式可变参数模板的传值计算可变参数模板参数个数参数包展开方式递归展开参数包逗号表达式展开参数包 emplace插入 可变参数模板是C11新增的最强大的特性之一&#xff0c;它对参数高度泛化&#xff0c;能够让我们创建可以接受可变参数的函数模板和类模板。 在…

【Less-CSS】初识Less,使编写 CSS 变得简洁

初识Less&#xff0c;使编写 CSS 变得简洁 1.Less简述2.LESS 原理及使用方式3.示例4.less语法5.Easy Less插件 作为一门标记性语言&#xff0c;CSS 的语法相对简单&#xff0c;对使用者的要求较低&#xff0c;但同时也带来一些问题&#xff1a;CSS 需要书写大量看似没有逻辑的代…

软件项目测试用例评审

软件项目测试用例评审是确保测试计划的一部分&#xff08;即测试用例&#xff09;满足项目质量和要求的关键步骤之一。以下是一个通用的软件项目测试用例评审流程&#xff0c;希望对大家有所帮助。北京木奇移动技术有限公司&#xff0c;专业的软件外包开发公司&#xff0c;欢迎…

Prometheus+Grafana可视化监控【Redis状态】

文章目录 一、安装Docker二、安装Redis数据库(Docker容器方式)三、安装Prometheus四、安装Grafana五、Pronetheus和Grafana相关联六、安装redis_exporter七、Grafana添加Redis监控模板 一、安装Docker 注意&#xff1a;我这里使用之前写好脚本进行安装Docker&#xff0c;如果已…

计网第五章(运输层)(八)(TCP的连接释放)

目录 一、基本概述 二、具体实现 三、经典问题之为什么客户进程不直接进入关闭状态&#xff1f; 四、保活计时器 一、基本概述 上篇博客&#xff08; 计网第五章&#xff08;运输层&#xff09;&#xff08;七&#xff09;&#xff08;TCP的连接建立&#xff09;&#xff…

Wiki.js - 下一代的开源Wiki软件

简介&#xff1a;在众多开源的Wiki软件中&#xff0c;Wiki.js无疑是一个独特且现代的选择。基于Node.js构建&#xff0c;使用了最新的Web技术&#xff0c;Wiki.js为用户提供了一个美观且功能丰富的界面&#xff0c;同时还保留了强大的扩展性和自定义性。无论你是为个人、团队或…

硬件故障诊断:快速定位问题

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…

Java IO流实现文件复制

目录 前言 文件复制底层逻辑 代码实现 ​编辑 重点&#xff01;&#xff01;&#xff01; 完整代码 改善思考 前言 Windows文件复制时我们是使用Ctrl C复制Ctrl V粘贴&#xff0c;上一篇文章Java基础入门对存储文件的相关操作 我们学习了Java IO流对文件的读写操作&…

uploadifive上传工具php版使用

uploadifive自带的DEMO文件。 下载地址&#xff1a; http://www.uploadify.com/download/ <!DOCTYPE HTML> <html> <head> <meta http-equiv"Content-Type" content"text/html; charsetutf-8"> <title>UploadiFive Test&…

MQ - 24 Pulsar集群架构设计与实现

文章目录 导图概述集群构建主节点弱 ZooKeeper 实现数据可靠性安全控制传输加密端到端加密身份认证资源鉴权可观测性总结导图 概述 从设计定位上来看,Pulsar 是作为 Kafka 的升级替代品出现的,它主要解决了 Kafka 在集群层面的弹性和规模限制问题。那么现在我们就从集群的角…

STM32实现PMBus从机程序

最近在野火的STM32F103VET6开发板上实现PMBus从机程序&#xff0c;这个程序参考了以下这篇博客的关于使用中断法实现I2C从机程序&#xff1a;STM32设置为I2C从机模式_iic从机_柒壹漆的博客-CSDN博客 &#xff0c;实测这个程序是可以正常运行的&#xff0c;感谢博主的分享&#…

3.wifi开发,网络编程

网络协议栈LwIP WiFi UDP Clinet编程 WiFi UDP Server编程 WiFi TCP Client编程 WiFi TCP Server编程 一。LWIP原理介绍&#xff0c;API介绍&#xff0c;文件结构 1.Lwip支持的协议 2.API 3.文件结构 1.api目录&#xff1a;应用程序接口文件。 2.arch目录&#xff1a;与硬件和…

k8s master 是如何进行pod的调度的

Master 节点将 Pod 调度到指定的 Node 节点的原理 该工作由 kube-scheduler 来完成&#xff0c;整个调度过程通过执行一些列复杂的算法最终为每个 Pod 计算出一个最佳的目标 Node&#xff0c;该过程由 kube-scheduler 进程自动完成。常见的有轮询调度&#xff08;RR&#xff09…