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
也许是忽略了装饰者 –