让Postgres的编码和测试变得有乐趣:pypgTAP

jopen 9年前

哦了测试存储过程和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.

项目主页:http://www.open-open.com/lib/view/home/1418787193058