0
我有這樣的:使用Python單元測試與monkeyrunner VS不monkeyrunner
import unittest
import sys, os
sys.path.append(os.path.dirname(sys.argv[0]))
class TestStringMethods(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.g = "def"
print cls
def test_upper(self):
self.assertEqual('DeF'.lower(), TestStringMethods.g)
if __name__ == '__main__':
unittest.main()
這
python test.py
給出:
python screen_test.py
<class '__main__.TestStringMethods'>
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
但是,這樣的:
monkeyrunner "%CD%\test.py"
給出:
E
======================================================================
ERROR: test_upper (__main__.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\abc\def\ghi\jkl\test.py", line 29, in test_upper
self.assertEqual('DeF'.lower(), TestStringMethods.g)
AttributeError: type object 'TestStringMethods' has no attribute 'g'
----------------------------------------------------------------------
Ran 1 test in 0.024s
FAILED (errors=1)
爲什麼同樣的測試時monkeyrunner運行失敗?
另外哪裏來的是唯一的E
來自哪裏?
但爲什麼monkeyrunner不能調用setUpClass()方法? – abc
也許是忽略了裝飾者 –