宋江亲自给索超解绑,劝其归顺了梁山。
宋江一天晚上做梦,梦见晁盖让说他背上之事发了,只有江南地灵星可免无事。宋江与吴用讲了这件事,第二天就发烧不起,背上长了毒疮。张顺说安道全可以治这个病,于是派张顺到江南找安道全。
张顺到了杨子江边,上了一艘渡船,因为连日赶路辛苦,吃了一碗饭倒头就睡了。结果被船家张旺绑了,到了江心给扔江里去了。张顺咬断绳子,游到南岸。见到了活闪婆王定六,给了张顺一身衣裳,并杀鸡置酒招待。
张顺杨子江上被打劫,真是阴沟里帆船。俗话说小心驶得万年船,项目测试非常重要。
测试框架pytest学习与实践
在维护和构建大型项目时,单独一个一个手工测试代码已经不适用了,这时候就要用专门的测试框架进行测试。
pytest是一个专业的测试框架,可以帮助我们对python项目进行测试,提高测试的效率。
pytest官网手册:pytest: helps you write better programs — pytest documentation
中文手册:Pytest 教程
入门学习
安装pytest
pip install pytest
写例子test_sample.py
def inc(x): return x + 1 def test_answer(): assert inc(3) == 5 def test_answer2(): assert inc(3) == 4
注意里面的测试函数都是test_开头,按照pytest的规范,需要以“test”4个字母开头的函数才会被测试。
执行测试
pytest test_sample.py
显示:
==================================== FAILURES ===================================== ___________________________________ test_answer ___________________________________ def test_answer(): > assert inc(3) == 5 E assert 4 == 5 E + where 4 = inc(3) test_sample.py:9: AssertionError ============================= short test summary info ============================= FAILED test_sample.py::test_answer - assert 4 == 5 =========================== 1 failed, 1 passed in 0.20s ===========================
可以看到,两个测试函数,assert inc(3) == 5的这个没有测试通过。
pytest提高篇
当前目录和子目录的所有类似
test_*.py
或*_test.py
的文件,都会自动参与测试。比如我们在当前目录下,再写一个文件test_sysexit.py:
# content of test_sysexit.py import pytest def f(): raise SystemExit(1) def test_mytest(): with pytest.raises(SystemExit): f()
然后在当前目录直接执行pytest命令,则会自动测试test_sample.py test_sysexit.py这两个文件,并给出测试结果:
collected 3 items test_sample.py F. [ 66%] test_sysexit.py . [100%] ==================================== FAILURES ===================================== ___________________________________ test_answer ___________________________________ def test_answer(): > assert inc(3) == 5 E assert 4 == 5 E + where 4 = inc(3) test_sample.py:9: AssertionError ============================= short test summary info ============================= FAILED test_sample.py::test_answer - assert 4 == 5 =========================== 1 failed, 2 passed in 0.46s ===========================
在kotti项目里集成测试
在Kotti项目中进行pytest测试可以参考这个文档:以Kotti项目为例使用pytest测试项目-CSDN博客
下载安装Kotti库
pip install https://atomgit.com/skywalk/Kotti cd Kotti pip install -r requirements.txt python3 setup.py develop --user
安装好pytest和其需要的库
pip install pytest pip install mock pip install pytest-flake8 pytest-cov pip install webtest zope.testbrowser
执行测试
~/github/Kotti]$ pytest
输出类似:
pytest
=============================== test session starts ===============================
platform linux -- Python 3.10.12, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/skywalk/github/kotti
configfile: pytest.ini
plugins: cov-5.0.0, flake8-1.1.1, Kotti-2.0.10.dev0
collected 454 itemskotti/__init__.py F
kotti/alembic/env.py F
kotti/alembic/versions/1063d7178fa_add_node_path_column.py Fkotti/tests/__init__.py F
kotti/tests/conftest.py F
kotti/tests/test_app.py F................
kotti/tests/test_cache.py F......F表示测试失败,后面的绿点表示测试成功,每个文档第一个测试是flake8,这个可以先不用去管,具体见文档:pytest的时候输出一个F后面跟很多绿色的点解读-CSDN博客
最后,应该将
pytest
测试集成到你的持续集成/持续部署(CI/CD)流程中,这样每次代码变更时都会自动运行测试。这有助于及早发现和修复问题,保持代码的健康和稳定。
张顺去健康府找安道全,安道全放不下相好的李巧奴,不想去梁山。可巧晚上张旺来找安道全李巧奴,张顺杀了虔婆、两个下人和李巧奴,却让张旺跑了。于是满屋写下杀人者安道全,这样安道全只好跟张顺去梁山。
过河又遇到张旺,张顺说我生在浔阳江边,长在小孤山下,做卖鱼牙子,天下闻名!跟了宋江之后纵横天下,谁不怕我!结果你竟然敢打劫我,要不是我会水,就没命了。最后说饶你不得,然后把张旺手脚捆在一起,丢到了江中。
安道全是个文人,走路慢,在一家店里碰见神行太保戴宗。戴宗说宋江都快死了,于是做法带着安道全先走了。张顺在店里歇了两三天,碰到了赶来的王定六,于是跟王定六一起回了梁山。
安道全到了梁山,很快就把宋江病治好了。宋江想打大名救卢俊义,安道全说疮口刚好,不能轻易运动。吴用也劝宋江好好休息调理,说初春的时候就能打下大名城。
吴用怎么打大名,且听下回分解。