【发布时间】:2017-02-25 01:39:50
【问题描述】:
我有这个:
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来自哪里?
【问题讨论】:
标签: android python python-2.7 unit-testing monkeyrunner