让Postgres的编码和测试变得有乐趣:pypgTAP
哦了测试存储过程和SQL查询你需要:
- 搭建 postgres 环境.
- 创建一个测试服务器.
- 测试环境需要设置
- 所有的测试套件需要测试和Rollbacked(关键)。
- 测试数据需要添加. YAAAAAWNNN!
- CI 集成, Docker. YAAAAAAAAWNNNN!
这就是所需要的大量工作!幸运的是pypgTAP能够解决了很多这些问题。
- Oh And did we mention its in python ?
它是如何做到的呢?
- 它启动一个使用后可抛弃的postgres服务器,来执行你的测试。然后并丢弃服务器和它的文件。
- pypgTAP可以在你的Postgres的代码库中,以一种相互隔离的方式来运行多个测试套件。
- Virtualenv python support: The industry standard for using python is virtualenv and tox and its a pain to use pgTAP with python. Remember plpython procedures execute on the postgres server and it cannot find python procedures executed by a client like psql Example:
CREATE OR REPLACE FUNCTION somefunction(arg1 varchar, arg2 varcha...) RETURNS varchar AS $$ print 'Hello World' import myutility -- import error if myutility is not found in global site-packages $$ LANGUAGE plpythonu strict;
- The virtualenv sharing also facilitates reuse of existing python code base, And hey we all just want an excuse to write in pure python :)
- It also makes it easy for people to do SDLC in pure python when its necessary and just use it seamlessly from within postgres's plpythonu.
- You can refer to resources within your project root in your unit tests and pypgtap will find them for you.
- You can test standalone SQL code (Like for Postgres Derivatives like redshift that don't support stored procedures) or test stored procedures.
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!