【发布时间】:2017-07-14 12:48:23
【问题描述】:
我正在尝试重现 http://twistedmatrix.com/documents/current/core/howto/trial.html 上“使用 Twisted 进行测试驱动开发”的示例。
我创建了文件:
calculus/__init__.py
calculus/base_1.py
calculus/test/__init__.py
calculus/test/test_base_1.py
我修改了 PYTHONPATH:
[xxx@zzz calculus]$ PYTHONPATH="$PYTHONPATH:`pwd`/.."
我调用了审判:
[xxx@zzz twistedm]$ trial calculus.test.test_base_1
calculus
test
test_base_1 ... [ERROR]
===============================================================================
[ERROR]
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/twisted/trial/runner.py", line 602, in loadByNames
things.append(self.findByName(name))
File "/usr/lib/python2.7/site-packages/twisted/trial/runner.py", line 406, in findByName
return reflect.namedAny(name)
File "/usr/lib/python2.7/site-packages/twisted/python/reflect.py", line 307, in namedAny
raise ObjectNotFound('%r does not name an object' % (name,))
twisted.python.reflect.ObjectNotFound: 'calculus.test.test_base_1' does not name an object
calculus.test.test_base_1
-------------------------------------------------------------------------------
Ran 1 tests in 0.199s
FAILED (errors=1)
Python 没有找到我的模块。
但如果我调用 python shell 并尝试导入我的模块,python 会导入它们。
然后我将一行“sys.path.append('/home/xxx/twistedm/calculus/..')”添加到文件“/usr/lib/python2. 7/site-packages/twisted/python/reflect.py”。现在一切正常。
所以我发现 Trial 在 sys.path 中查找模块,并且在命令行上设置 PYTHONPATH 对 sys.path 没有影响。
问题是如何在调用 Trial 时从命令行修改 sys.path。
【问题讨论】:
标签: python twisted pythonpath trial sys.path