【发布时间】:2014-05-19 08:11:46
【问题描述】:
到现在我们都是用这个来获取方法调用者的模块:
frame=inspect.currentframe().f_back
module=inspect.getmodule(frame.f_code)
它运行良好,除了在 py.test TestCases 中。
Py.test 将文件名作为模块名返回。
我们的测试代码布局:
foomodule/lib/examplecode.py
foomodule/tests/test_examplecode.py
如果在examplecode.py 中调用,结果是'foomodule'。但是在test_examplecode.py 中调用它会返回'test_examplecode'。
【问题讨论】:
标签: python introspection pytest