我有一个函数测试'y1.py',我试图从python/django函数中向它传递参数。在调用函数中我有:
import unittest, sys
import ft1.y1
ft1.y1.testVars = [1, 2, 3, "foo"]
unittest.main(module=ft1.y1, argv=sys.argv[:1], exit=False)
基于h。ttp://stackoverflow.com/questions/2812132/how-to-pass-variables-using-unittest-suite在
y1.py:
^{pr2}$我得到了:
Traceback (most recent call last):
File "F:\envs\r1\driver1\ft1\y1.py", line 17, in setUp
print('tvars '+ y1.testVars )
AttributeError: type object 'y1' has no attribute 'testVars'
----------------------------------------------------------------------
Ran 1 test in 2.330s
FAILED (errors=1)
[02/Feb/2014 23:59:42] "GET /runtest/ HTTP/1.1" 200 7
我该怎么解决这个问题?在
编辑:
按照建议,我将行改为:
print('tvars' + sys.module[__name__].testVars )
我得到了:
E
======================================================================
ERROR: test_y1 (ft1.y1.y1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "F:\envs\r1\driver1\ft1\y1.py", line 17, in setUp
print('tvars' + sys.module[__name__].testVars )
AttributeError: 'module' object has no attribute 'module'
----------------------------------------------------------------------
Ran 1 test in 2.981s
FAILED (errors=1)
如果您试图引用模块而不是类(您的
testVars
在模块级别),您可能应该使用sys.modules[__name__].testVars
,这使得:成为:
^{pr2}$相关问题 更多 >
编程相关推荐