class TestUM:
@classmethod
def setup_class(will):
""" Setup Class"""
will.var = "TEST"
def setup(this):
""" Setup """
print this.var
def test_number(work):
""" Method """
print work.var
def teardown(orr):
""" Teardown """
print orr.var
@classmethod
def teardown_class(nott):
""" Teardown Class """
print nott.var
按以下方式运行
nosetests -v -s test.py
我不是Python专家,但我不明白为什么上面的代码可以完美地使用nose。每一张打印“测试”。这里到底发生了什么。你知道吗
在实例方法中,第一个参数是实例本身。你知道吗
在类方法中,第一个参数是类本身。你知道吗
在您的例子中,不是将该参数命名为
self
或cls
(约定),而是将其命名为this
、work
、orr
和nott
。但是他们都得到了相同的参数,不管参数的名称是什么。你知道吗您已经成功地将属性
var
设置为"TEST"
,因此他们都能正确地看到它。你知道吗不使用类的示例函数:
调用这些函数:
参数的名称无关紧要。重要的是参数指向什么,它总是实例或类
相关问题 更多 >
编程相关推荐