“NoneType”对象没有属性“tttttt”

2024-06-11 21:50:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我对那个代码有问题。怎么了?在

class test(osv.osv):
    _name = "test"    
    _description = "uuuu"    

    def tttttt():
        return "testtt"

test() 

instance = test()
print (instance.tttttt())

Tags: instance代码nametestreturndefdescriptionclass
1条回答
网友
1楼 · 发布于 2024-06-11 21:50:06

有趣的问题。经过一番挖掘,OpenERP框架似乎对对象创建机制做了一些奇怪的事情。对于BaseModel的子类,比如osv.osv和您的类,^{} method只在池中注册该类并返回None。在

您可以通过稍微修改print语句来确认这一点。在

instance = test()
print instance is None # will print True.

据我所知,OpenERP模型类不能在服务器进程之外运行。如果您试图编写单元测试或其他东西,您要么必须编写单独的helper类并对其进行测试,要么使用YAML testing framework运行全面的集成测试。在

有关测试helper类的示例,请参阅我们的^{}模块。sim_*类是单元测试的助手,它们都由product_stockouts.py中的模型类调用。在

相关问题 更多 >