มีอะไรใช้แทน @expect ของ Junit4 บน test unit ของ Python หรือเปล่าครับ?

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1001 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1001 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

มีอะไรใช้แทน @expect ของ Junit4 บน test unit ของ Python หรือเปล่าครับ?

ผมจะใช้

try:
   do something 
   assert False
except:
   pass

ก็ดูแปลกๆ?

sugree's picture

ทำ decorator ก็ได้นะ หรือจะใช้ assert ก็ดี

assert False, func() == 0

veer's picture

อันนี้เรียกเดี่ยวใช้ได้ใส่ test unit เจ๊ง -_-'

sugree's picture

ใช้ unittest รึเปล่าเนี่ย

veer's picture

nosetest มันไปเรียก unittest อีกทีปะครับ?

class TestAnnotDocParser(object):
    def test_basic(self):
        parse("[-1 a ]")
 
    @expect(RuntimeError)
    def test_open_wo_close(self):
        parse("[-1 x")

อันที่มี @expect nose มันจะไม่ถูก test เลย. หรือพูดอีกอย่างคือตัวอย่างข้างบนจะเหลือแค่ test เดียว
---
http://openil.wordpress.com/

sugree's picture

สงสัยจะคนละตัว ใช้ unittest จะเขียนอีกแบบ

veer's picture
class TestAnnotDocParser(unittest.TestCase):
    @expect(ParsingError)
    def test_close_wo_open(self):
        expect(" x -]")

แบบนี้น่าจะ unittest แน่ๆ? ก็เจ๊งอยู่ดี.

---
http://openil.wordpress.com/

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น