问题
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