Is there a way for a Python Nose test to know its decorated attributes?

你离开我真会死。 提交于 2019-12-13 02:36:47

问题


I have some tests like:

@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')

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?


回答1:


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



来源:https://stackoverflow.com/questions/34618095/is-there-a-way-for-a-python-nose-test-to-know-its-decorated-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!