3
__init__ สำหรับ unittest.TestCase
ฉันต้องการเพิ่มบางสิ่งในสิ่งที่unittest.TestCaseชั้นเรียนทำเมื่อเริ่มต้น แต่ฉันคิดไม่ออกว่าจะทำอย่างไร ตอนนี้ฉันกำลังทำสิ่งนี้: #filename test.py class TestingClass(unittest.TestCase): def __init__(self): self.gen_stubs() def gen_stubs(self): # Create a couple of tempfiles/dirs etc etc. self.tempdir = tempfile.mkdtemp() # more stuff here ฉันต้องการให้สร้างต้นขั้วทั้งหมดเพียงครั้งเดียวสำหรับการทดสอบทั้งชุดนี้ ฉันไม่สามารถใช้งานได้setUpClass()เนื่องจากฉันกำลังทำงานกับ Python 2.4 (ฉันไม่สามารถทำงานบน python 2.7 ได้เช่นกัน) ฉันทำอะไรผิดที่นี่? ฉันได้รับข้อผิดพลาดนี้: `TypeError: __init__() takes 1 argument (2 given)` ... และข้อผิดพลาดอื่น ๆ เมื่อฉันย้ายทั้งหมดของรหัสต้นขั้วลงเมื่อผมทำงานกับคำสั่ง__init__python -m unittest …
122
python
unit-testing