有没有一种方法可以让Python鼻子测试了解其修饰的属性? [英] Is there a way for a Python Nose test to know its decorated attributes?
问题描述
我有一些测试,例如:
@attr('sanity', 'someothertag')
def test_this_important_feature(self):
"""Comment - Verify the very imporant feature
我想知道是否有一种方法可以从测试内部查看测试中的属性.另外(可能最好),是否有一种方法可以将每个测试的属性链接到鼻子找到的每个测试?对于上面的示例,它类似于:
I'm wondering if there's a way to see the attributes on the test from inside the test. Alternatively (and probably preferably), is there a way to link the attributes of each test to each test that Nose finds? For the above example, it'd be something like:
test_this_important_feature: ('sanity','someothertag')
我运行了所有这些测试,并使用"nose.run(配置)"捕获了结果-结果是否能够具有每个测试的属性?
I run all of these tests and capture the results with nose.run(configuration) - would the results be able to have the attributes for each test?
推荐答案
属性可以直接用作该函数的字典,即test_this_important_feature.__dict__
将具有所有属性.看看 get_attr_dict()在此答案中,如果您不想对功能名称进行硬编码.对于答案的第二部分,您还可以在用于精美的打印输出
Attributes are directly available as a dictionary of the function, i.e. test_this_important_feature.__dict__
will have all the attributes. Have a look at get_attr_dict() in this answer, if you do not want to hardcode the name of the function. For the second part of the answer, you may also expand on for fancy printout
这篇关于有没有一种方法可以让Python鼻子测试了解其修饰的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!