讓Postgres的編碼和測試變得有樂趣:pypgTAP

jopen 9年前發布 | 15K 次閱讀 pypgTAP PostgreSQL 數據庫服務器

哦了測試存儲過程和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.baiduhome.net/lib/view/home/1418787193058

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!