Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单元测试\uuuu单元测试\uu跳过\uuuuuu在测试前方法中的访问_Python_Unit Testing_Nose - Fatal编程技术网

Python 单元测试\uuuu单元测试\uu跳过\uuuuuu在测试前方法中的访问

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 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_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
中进行测试。非常感谢您的快速回复!