1

我有一个 python 模块和一个单元测试。当我运行单元测试时,我得到了这个:

flumotion
  test
    test_common_gstreamer ...                                           [ERROR]

===============================================================================
[ERROR]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/trial/runner.py", line 660, in loadByNames
    things.append(self.findByName(name))
  File "/usr/lib/python2.7/dist-packages/twisted/trial/runner.py", line 470, in findByName
    return reflect.namedAny(name)
  File "/usr/lib/python2.7/dist-packages/twisted/python/reflect.py", line 464, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File "/flumotion/flumotion/test/test_common_gstreamer.py", line 20, in <module>
    from gi.repository import Gst
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 23, in <module>
    from ._gi import _API, Repository
exceptions.ImportError: could not import gobject (error was: ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".',))

flumotion.test.test_common_gstreamer

我知道错误是不言自明的,但我找不到“导入 gobject”发生的位置,所以我被建议制作一个导入钩子,它会在任何时候进行导入时打印。我不知道在哪里以及如何实现钩子,我只在这里http://xion.org.pl/2012/05/06/hacking-python-imports/阅读了一些关于导入钩子的内容。任何帮助表示赞赏

4

0 回答 0