Python 单元测试\uuuu单元测试\uu跳过\uuuuuu在测试前方法中的访问
我正在使用skip decorator进行测试:Python 单元测试\uuuu单元测试\uu跳过\uuuuuu在测试前方法中的访问,python,unit-testing,nose,Python,Unit Testing,Nose,我正在使用skip decorator进行测试: @skip('I want this to skip') def test_abc(self): 我也有一个nose插件,可以用定义的 def beforeTest(self, *args, **kwargs): 测试用例test\u abc被beforeTest方法捕获。如何在我的beforeTest方法中检查decorator值 我看到unittest decorator的定义有以下代码: test_item.__unittest_ski
@skip('I want this to skip')
def test_abc(self):
我也有一个nose插件,可以用定义的
def beforeTest(self, *args, **kwargs):
测试用例test\u abc
被beforeTest
方法捕获。如何在我的beforeTest
方法中检查decorator值
我看到unittest decorator的定义有以下代码:
test_item.__unittest_skip__ = True
test_item.__unittest_skip_why__ = reason
但是我不知道如何在测试前从访问它。
运行args[0]时,test
具有测试用例对象,但我似乎可以找到定义\uuuuuu unittest\uuuu skip\uuuu
的位置
谢谢 看看源代码,似乎没有一种干净的方法可以做到这一点TestCase
似乎知道它基于实现细节测试的是什么方法。如果您有一个对正在运行的测试用例的引用(可能是args[0]。test
?我不熟悉nose
…),您可以使用它,也可以从中的返回值解析它。假设你不是在做一件很时髦的事情,它会是这样的:
test_name = test_case.id().rsplit('.', 1)[-1]
test_method = getattr(test_case, test_name)
if getattr(test_method, '__unittest_skip__', False):
# Method skipped. Don't do normal stuff.
你问的实际问题有点不清楚。考虑修改你的帖子。完美!它确实有效,对正在运行的测试用例的引用来自args[0]。在beforeTest
中进行测试。非常感谢您的快速回复!