首页 文章 精选 留言 我的

精选列表

搜索[javascript框架],共10000篇文章
优秀的个人博客,低调大师

CDF 欢迎 Shipwright 作为新的孵化项目,Kubernetes 容器镜像构建框架

CDF(持续交付基金会,Continuous Delivery Foundation)[1]是一个开源软件基金会,致力于提高全球安全、快速交付软件的能力,该基金会今天宣布Shipwright[2]已成为 CDF 的一个孵化项目。 可靠、安全、高效地构建容器镜像是现代云原生交付流水线日益重要的功能。使用 Shipwright,开发人员可以通过定义一个不需要任何容器或容器工具知识的最小 YAML,获得一种构建容器镜像的简化方法。Shipwright 是基于 Tekton 构建的,Tekton 是一个 CDF 项目。 Shipwright 仓库和安装说明在这里:https://github.com/shipwright-io/build “加入 CDF 是 Shipwright 社区的一个重要里程碑。作为 Tekton(CDF 的创始项目之一)的联合创始人,我相信 CDF 是 Shipwright 实现 v1,更重要的是,超越 v1 的正确平台。”红帽高级首席软件工程师和 Shipwright 贡献者 Jason Hall 说。“我们相信 Shipwright 将成为持续交付生态系统中的重要工具。Shipwright 试图做好一件事:构建容器镜像。这不是一把瑞士军刀,这是一把锤子。” Shipwright 基于多年来作为 Red Hat OpenShift 平台的一部分开发和操作 Red Hat OpenShift 构建的经验,IBM 云代码引擎团队也做出了贡献。Shipwright 支持 IBM 云代码引擎容器镜像构建。 “Shipwright 专注于做一件非常好的事情:构建容器。开发人员需要良好的工具来构建云原生应用程序,Shipwright 是该工具集的出色补充。由于 Shipwright 与 Tekton 合作良好,Tekton 是 CDF 的创始项目之一,也是发展最快的项目之一,因此 Shipwright 加入 CDF 进行更密切的合作是很有意义的。”CDF 执行董事 Tracy Miranda 说。“我们很高兴与 Shipwright 密切合作,帮助构建项目并扩大其用户社区。欢迎整个 Shipwright 社区!” CDF 提供了广泛的服务来支持开放源码项目,而项目启动过程是作为孵化项目。这适用于那些对实现广泛采用感兴趣并已为此确定了增长计划的项目。项目接受 CDF 技术监督委员会(TOC)的指导,并被期望积极开发社区的贡献者、治理、项目文档等等。关于将开源持续交付项目引入 CDF 的详细信息可以在这里[3]找到。 “TOC 非常高兴地欢迎 Shipwright 加入 CDF。我们一直在为向孵化项目过渡做准备,这次宣布是这一过程中的一个重要里程碑,”TOC 主席 Dan Lorenc 说。“欢迎!” Shipwright 为用户、贡献者、维护人员和任何对项目感兴趣的人举办每周会议。Shipwright 贡献指南以及关于社区会议和联系信息可以在这里[4]找到。 参考资料 [1]CDF(持续交付基金会,Continuous Delivery Foundation):https://cd.foundation/ [2]Shipwright:https://shipwright.io/ [3]这里:https://github.com/cdfoundation/toc/blob/master/PROJECT_LIFECYCLE.md#project-proposal-requirements [4]这里:https://github.com/shipwright-io/community/blob/main/CONTRIBUTING.md

优秀的个人博客,低调大师

pytest测试框架系列 - Pytest Fixture和conftest.py还能这样使用?

## 前言 Fixture是pytest的非常核心功能之一,在不改变被装饰函数的前提下对函数进行功能增强,经常用于测试用例前置和后置工作。与setup/teardown类似,但更强大灵活。 ## fixture的优势 - fixture命名方式灵活,不局限于 setup 和teardown 那几个命名规则 - conftest.py 配置里可以实现数据共享,能够自动搜索需要的fixture - fixture 配置不同的参数可以轻松实现跨文件、session会话共享 ## fixture工作原理 - 在普通函数上使用@Pytest.fixture()装饰器,声明函数为一个fixture函数 - 如果测试用例函数的参数列表中存在fixture的函数名或者使用@pytest.mark.usefixtures(fixture_name) - 在测试执行阶段,pytest执行用例之前执行fixture函数功能 - 如果fixture装饰的函数无返回值,相当于用例前置操作,否则相当于传参 - 如果fixture设置了后置操作,则用例执行完成后进行执行 ## fixture搜索顺序 - 第一步:优先搜索测试所在的模块 - 第二步:搜索模块同一文件路径下的conftest.py - 第三步:找不到再搜索上一层的conftest.py,直到项目根目录 ## fixture 函数说明 ```python def fixture( fixture_function: Optional[_FixtureFunction] = None, *, scope: "Union[_Scope, Callable[[str, Config], _Scope]]" = "function", params: Optional[Iterable[object]] = None, autouse: bool = False, ids: Optional[ Union[ Iterable[Union[None, str, float, int, bool]], Callable[[Any], Optional[object]], ] ] = None, name: Optional[str] = None, ) -> Union[FixtureFunctionMarker, _FixtureFunction]: """Decorator to mark a fixture factory function. This decorator can be used, with or without parameters, to define a fixture function. The name of the fixture function can later be referenced to cause its invocation ahead of running tests: test modules or classes can use the ``pytest.mark.usefixtures(fixturename)`` marker. Test functions can directly use fixture names as input arguments in which case the fixture instance returned from the fixture function will be injected. Fixtures can provide their values to test functions using ``return`` or ``yield`` statements. When using ``yield`` the code block after the ``yield`` statement is executed as teardown code regardless of the test outcome, and must yield exactly once. :param scope: The scope for which this fixture is shared; one of ``"function"`` (default), ``"class"``, ``"module"``, ``"package"`` or ``"session"``. This parameter may also be a callable which receives ``(fixture_name, config)`` as parameters, and must return a ``str`` with one of the values mentioned above. See :ref:`dynamic scope` in the docs for more information. :param params: An optional list of parameters which will cause multiple invocations of the fixture function and all of the tests using it. The current parameter is available in ``request.param``. :param autouse: If True, the fixture func is activated for all tests that can see it. If False (the default), an explicit reference is needed to activate the fixture. :param ids: List of string ids each corresponding to the params so that they are part of the test id. If no ids are provided they will be generated automatically from the params. :param name: The name of the fixture. This defaults to the name of the decorated function. If a fixture is used in the same module in which it is defined, the function name of the fixture will be shadowed by the function arg that requests the fixture; one way to resolve this is to name the decorated function ``fixture_ `` and then use ``@pytest.fixture(name=' ')``. """ """ 翻译: 可以使用此装饰器(带或不带参数)来定义fixture功能。 fixture功能的名称可以在后面使用引用它会在运行测试之前调用它:test模块或类可以使用 pytest.mark.usefixtures(fixturename标记)。 测试功能可以直接使用fixture名称作为输入参数,在这种情况下,夹具实例从fixture返回功能将被注入。 fixture可以使用``return`` or``yield`` 语句返回测试函数所需要的参数值,在``yield``后面的代码块 不管测试的执行结果怎么样都会执行 :arg scope: scope 有四个级别参数 "function" (默认), "class", "module" or "session". :arg params: 一个可选的参数列表,它将导致多个参数调用fixture功能和所有测试使用它 :arg autouse: 如果为True,自动执行fixture函数,所有函数都可以使用。 如果为False(默认值) 则手动使用fixture才能调用 :arg ids: 每个字符串id的列表,每个字符串对应于params 这样他们就是测试ID的一部分。 如果没有提供ID它们将从params自动生成 :arg name: fixture的名称。 默认为装饰函数的名称。 如果设置了name的值,在使用fixture时需要 使用设置的name,否则无法识别 """ ``` ## fixture参数详解 使用语法: ```python @pytest.fixture(scope = "function",params=None,autouse=False,ids=None,name=None) def login(): print("我是login函数") ``` ### scope 参数 - 说明:可以认为是fixture的作用域,默认:function,还有class、module、package、session四个 - 区别: 取值 | 范围|说明| -------- | -----|----- function| 函数级|每一个函数或方法都会调用 class| 类级|每个测试类只运行一次 module| 模块级|每一个.py文件调用一次 session| 会话级|每次会话只需要运行一次,一般用于打开浏览器、启动APP、登录等操作 #### **关注点** - fixture可以给函数和类使用 - fixture通过测试用例参数方式使用,这样fixture的返回值可以通过fixture名称作为参数传递给测试用例,也可以使用@pytest.mark.usefixtures("login")方式,但无法给测试用例传递fixture的返回值 - fixture函数内可以调用其他fixture函数,必须要通过函数参数方式 - 非测试用例的函数无法使用fixture 作用范围示例: #### **scope = "function"** ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 14:39 # @Author : king # @File :test_fixture.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(scope="function") def login(): print("我是login函数。。") return "king" # fixture内调用其他fixture @pytest.fixture(scope="function") def login_01(login): print("我是调用了 login的fixture函数") # 通过参数方式使用fixture def test_01(login): print("我是 test_01 测试用例\n") # 通过@pytest.mark.usefixtures("login")调用fixture @pytest.mark.usefixtures("login") def test_02(): print("我是 test_02 测试用例\n") # 通过参数方式使用调用其他fixture的fixture def test_03(login_01): print("我是 test_03 测试用例\n") # 给类使用fixture @pytest.mark.usefixtures("login") class TestFixture: def test_one(self): print("我是类里面的 test_one 测试用例") def test_two(self): print("我是类里面的 test_two 测试用例") # 非test开头函数调用fixture def reg_01(login): print("我是reg函数\n") # 非test开头函数使用@pytest.mark.usefixtures("login")调用fixture @pytest.mark.usefixtures("login") def reg_02(): print("我是reg函数\n") if __name__ == '__main__': pytest.main(["-s", "test_fixture.py"]) ``` 执行结果为: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210703162628889.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) #### **scope = "class"** 示例: ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 15:35 # @Author : king # @File :test_fixture_class.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(scope="class") def login(): print("我是login函数。。") return "king" # 通过参数方式使用fixture def test_01(login): print("我是 test_01 测试用例\n") # 通过参数方式使用fixture def test_02(login): print("我是 test_02 测试用例\n") @pytest.mark.usefixtures("login") class TestFixture: def test_one(self): print("我是类里面的 test_one 测试用例") def test_two(self): print("我是类里面的 test_two 测试用例") if __name__ == '__main__': pytest.main(["-s", "test_fixture_class.py"]) ``` 执行结果: ![在这里插入图片描述](https://img-blog.csdnimg.cn/202107031650089.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) #### **scope = "module"** 示例: ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 16:52 # @Author : king # @File :test_fixture_module.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(scope="module") def login(): print("我是login函数。。") return "king" # 通过参数方式使用fixture def test_01(login): print("我是 test_01 测试用例\n") # 通过参数方式使用fixture def test_02(login): print("我是 test_02 测试用例\n") @pytest.mark.usefixtures("login") class TestFixture: def test_one(self): print("我是类里面的 test_one 测试用例") def test_two(self): print("我是类里面的 test_two 测试用例") if __name__ == '__main__': pytest.main(["-s", "test_fixture_module.py"]) ``` 执行结果为: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210703165414402.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) #### **scope = "session"** - 注意:session代表会话级,就是从启动测试到结束测试,看作为一次session会话,scope = "session"使用到后面conftest.py详细讲解 ### params 参数 - fixture的可选形参列表,支持列表传入 - params 参数包含几个,调用时就会执行几次 - 可与参数ids一起使用,作为每个参数的标识,详见ids - 需要使用时,参数调用写法固定为:Request.param 示例: ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 17:13 # @Author : king # @File :test_fixture_params.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(params=[1, 2, 3, 4, 5]) def login(request): print("我是login函数。。") return request.param # 通过参数方式使用fixture def test_01(login): print("我是 test_01 测试用例-params- {}\n".format(login)) if __name__ == '__main__': pytest.main(["-s", "test_fixture_params.py"]) ``` 执行结果: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210703172128170.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) ### autouse 参数 - 默认False - 如果设置为True,则每个测试函数都会自动调用该fixture,无需传入fixture函数名,作用范围跟着scope走(注意使用) 示例: ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 17:25 # @Author : king # @File :test_fixture_autouse.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(autouse=True) def login(): print("我是login函数。。") # 通过参数方式使用fixture def test_01(): print("我是 test_01 测试用例\n") if __name__ == '__main__': pytest.main(["-s", "test_fixture_autouse.py"]) ``` 执行结果: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210703172748643.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) ### ids 参数 - 用例标题,需要与params配合使用,一对一关系 **未配置ids时:** ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 17:29 # @Author : king # @File :test_fixture_ids.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(params=[1, 2, 3]) def login(request): return request.param # 通过参数方式使用fixture def test_01(login): print("我是 test_01 测试用例\n") if __name__ == '__main__': pytest.main(["-s", "test_fixture_ids.py"]) ``` 执行结果: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210703173751276.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) **配置了ids的示例:** ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 17:29 # @Author : king # @File :test_fixture_ids.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(params=[1, 2, 3], ids=["case01", "case02", "case03"]) def login(request): return request.param # 通过参数方式使用fixture def test_01(login): print("我是 test_01 测试用例\n") if __name__ == '__main__': pytest.main(["-s", "test_fixture_ids.py"]) ``` 执行结果: ![在这里插入图片描述](https://img-blog.csdnimg.cn/2021070317350821.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) **问题:** 当我们多个测试用例文件(test_*.py)的所有用例都需要用登录、打开浏览器、启动APP等功能来作为前置操作,那就不能把登录、打开浏览器、启动APP功能写到某个用例文件,如何解决呢? 解决方案:引入conftest.py文件,为了解决上述问题,单独管理一些全局的fixture ## conftest.py使用 说明: - pytest会默认读取conftest.py里面的所有fixture - conftest.py 文件名称是固定的,不能随意改动 - conftest.py只对同一个package下的所有测试用例生效,并且有__init__.py文件 - 不同目录可以有自己的conftest.py,一个项目中可以有多个conftest.py - pytest会自动查找项目中的conftest.py文件,逐层往上查找 示例: - 项目目录 ```bash case │ conftest.py │ __init__.py │ ├─case01 │ conftest.py │ test_01.py │ __init__.py │ └─case02 conftest.py test_02.py __init__.py ``` case/conftest.py ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 18:04 # @Author : king # @File :conftest.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(scope="session") def login(): print("我是case目录的login") @pytest.fixture(scope="session") def open_browser(): print("我是case目录的 open_browser") ``` case01/conftest.py ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 18:06 # @Author : king # @File :conftest.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(scope="session") def login(): print("我是case01目录的login") ``` case01/conftest.py ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 18:04 # @Author : king # @File :test_01.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 def test_01(login): print("我是case01 里面test_01 测试用例") def test_02(open_browser): print("我是case01 里面test_02 测试用例") ``` case02/conftest.py ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 18:07 # @Author : king # @File :conftest.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 import pytest @pytest.fixture(scope="session") def _login(): print("我是case02 目录的login") ``` case02/test_02.py ```python # _*_coding:utf-8 _*_ # @Time :2021/7/3 18:04 # @Author : king # @File :test_02.py # @Software :PyCharm # @blog :https://blog.csdn.net/u010454117 # @WeChat Official Account: 【测试开发知识库】 def test_02(login): print("我是case02的 test_02 测试用例") ``` 在case目录下,执行 `pytest -s` ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210703184758924.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70) **注意点** - 外层的fixture不能调用内层的fixture - 不同包下面的fixture只能当前包使用,不能被其他包使用,例如case01下面的fixture不能被case02的测试函数使用 ---- 以上为内容纯属个人理解,如有不足,欢迎各位大神指正,转载请注明出处! >**如果觉得文章不错,欢迎关注CSDN和微信公众号** > >微信公众号: ![微信公众号](https://img-blog.csdnimg.cn/2021063023022778.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA0NTQxMTc=,size_16,color_FFFFFF,t_70)

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

用户登录
用户注册
修改密码
忘记密码