【问题标题】:Is there a way for a Python Nose test to know its decorated attributes?有没有办法让 Python Nose 测试知道它的修饰属性?
【发布时间】:2016-01-06 13:34:47
【问题描述】:

我有一些测试,例如:

@attr('sanity', 'someothertag')
def test_this_important_feature(self):
    """Comment - Verify the very imporant feature

我想知道是否有办法从测试内部查看测试的属性。或者(可能最好),有没有办法将每个测试的属性链接到 Nose 找到的每个测试?对于上面的例子,它会是这样的:

test_this_important_feature: ('sanity','someothertag')

我运行所有这些测试并使用 nose.run(configuration) 捕获结果 - 结果是否能够包含每个测试的属性?

【问题讨论】:

    标签: python unit-testing nose


    【解决方案1】:

    属性可以直接作为函数的字典使用,即test_this_important_feature.__dict__ 将具有所有属性。如果您不想硬编码函数的名称,请查看此答案中的get_attr_dict()。对于答案的第二部分,您还可以扩展for fancy printout

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 2012-02-17
      • 2011-04-15
      • 1970-01-01
      • 2021-02-28
      • 2012-11-19
      相关资源
      最近更新 更多