Python 使用多种设置重构鼻子测试
假设您得到了以下测试代码,其中Python 使用多种设置重构鼻子测试,python,nose,Python,Nose,假设您得到了以下测试代码,其中test1和test2方法在grid对象上运行一些测试 N = 10 grid = Grid(N) def test1(): ... def test2(): ... 为N=11添加测试的最佳方法是什么,以便在新对象上运行相同的方法test1和test2?当然,可以简单地创建一个新文件,如下所示 N = 11 grid = Grid(N) def test1(): ... def test2(): ... 但是这会导致大量
test1
和test2
方法在grid
对象上运行一些测试
N = 10
grid = Grid(N)
def test1():
...
def test2():
...
为N=11
添加测试的最佳方法是什么,以便在新对象上运行相同的方法test1和test2?当然,可以简单地创建一个新文件,如下所示
N = 11
grid = Grid(N)
def test1():
...
def test2():
...
但是这会导致大量代码重复。使用全局变量是一种设置测试用例的棘手方法。您应该将测试重构为如下内容
def test1(N):
grid = Grid(N)
...
def test2(N):
grid = Grid(N)
...
从这里开始,您似乎想看看中包含的nose