Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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 使用多种设置重构鼻子测试_Python_Nose - Fatal编程技术网

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