任何时候进行导入的导入挂钩

时间:2013-06-19 14:21:22

标签: python import-hooks

我有一个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

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

0 个答案:

没有答案