Pytest 源码解读 [0] - Kickoff 篇
source link: https://markshao.github.io/2019/08/10/pytest-source-analysis/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Pytest 源码解读 [0] - Kickoff 篇
Pytest 源码解读
之前定的目标,2019 年要完成 pytest
的源码解读,实在是因为之前太忙耽搁下来,眼看已经到了8月份,再不开始的话估计就要黄了 (之前信誓旦旦立的Flag不能轻易打破)。其实时间挤挤也总是有的,不能再找借口了。而且估计未来也不会再去看 pytest 的source code 了,就当给自己的 Pytest 这段经历做个总结吧。
Python 在测试框架的选择上主要是3个
- unittest
- pytest
unittest
是 python 自带的一个轮子,一般常用的需求都能满
nose
(https://nose.readthedocs.io/en/latest/) 是一个第三方的测试框架,之前在emc
和 greenplum
团队一起搞了一个项目是基于 nose 的,感觉功能要比 unittest 要复杂一些,不够我没有用的太深入,也没资格点评
pytest
是我加入到 Splunk 的时候开始接触的,Splunk 当时内部有一个叫 Helmut
的框架,就是基于 pytest
来打造的 。这也是我第一次知道Pytest,刚开始最不习惯的使用 Fixture
, 后来才慢慢品味到了 Fixture
这种 Lazy Loading 的设计价值。后来基本上我就一直在用 Pytest 了,而且在依图的时候团队写了一个 Fixture Factory
的 module ,进一步简化了 Fixture 的使用和管理复杂度。当然这次主要是聚焦在 Pytest 的源码分析上,至于 Pytest 的使用,大家自己看 Pytest 的官方文档吧。
一些周边信息
Holger Krekel
- Pytest 的作者,其实 Pytest 最开始的名字叫
Py.test
- 他是个德国人,同时还是
PyPy
和tox
的作者
Pluggy
- (https://github.com/pytest-dev/pluggy)
- Pytest 的核心实际的基于
Pluggy
这个 plugin framework 的,实际上 pytest 本身就是由一个一个插件组成的 - 本来 pluggy 的代码是在 pytest 的 repo 里,后来迁移了出来,作为一个独立的项目。Pluggy 作为一个独立的plugin framework 来看也是很优雅的存在
源码分析计划
主要是分两步走
- Pluggy 的分析,这个是 Pytest 的核心引擎
- Pytest 分析
Recommend
-
3
pytest 是如何测试 pytest 的Pytest 源码解读 [5] - pytest 是如何测试 pytest 的 2021-06-05|
-
2
pluggy "_HookCall" 调用链分析Toggle siteCatalogYou've read100%Pytest 源码解读 [4] - pluggy "_Hoo...
-
4
[pluggy] plugin 注册逻辑分析Toggle siteCatalogYou've read100%Pytest 源码解读 [3] - [pluggy] plug...
-
3
Pytest 源码解读 [2] - [pluggy] 核心设计理念和代码结构 2019-10-02|
-
4
今天是祖国母亲的70华诞,早上在家里和媳妇一起看了令人激动的阅兵,真心为自己做位一个中国人而自豪。国庆的上海天气有点操蛋,受到台风的影响外面是大风大雨,不过因为媳妇怀孕的原因本来也没计划出去玩,趁着难得的假期,在家喝喝茶,吃吃东西,写写博客,把的之...
-
6
Pytest 源码解读 [5] - pytest 是如何测试 pytest 的 什么叫用 pytest 来测试 pytest 呢?其实就是构建一个 mini 的 pytest 集成测试环境。我们要对一个测试框架做端到端的测试,最基本的...
-
7
其实本来想介绍下 tryfirst , trylast 这几个特性和实现的,不过仔细看了下实现,发现 pytest 在插件的执行顺序上还有挺多巧妙的设计可以讲的。为了更好理解插件存储的顺序,我主要想介绍下下面几个部分 什么...
-
4
Pytest 源码解读 [7] - PyTest on pluggy 之前花了很多篇幅来介绍 pluggy 这个插件框架。核心原因就是因为其实 pytest 是一个完全基于 pluggy 开...
-
6
上一节讲到如何安装和使用第三方插件,用法很简单。接下来解读下如何自己开发pytest插件。 但是,由于一个插件包含一个或多个钩子函数开发而来,所以在具体开发插件之前还需要先学习hooks函数。
-
9
【pytest官方文档】解读- 开发可pip安装的第三方插件 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK