Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/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 pytest在类中以正确的顺序运行场景_Python_Pytest - Fatal编程技术网

Python pytest在类中以正确的顺序运行场景

Python pytest在类中以正确的顺序运行场景,python,pytest,Python,Pytest,因此,我有以下结构: class Test(object): def test_1(self): pass def test_2(self): pass def test_3(self): pass 它运行得很好,现在我添加了“场景”(正如在中推荐的): 当我运行它时,测试顺序错误,我得到: test_1[1] test_1[2] test_2[1] test_2[2] test_3[1] test_3[2]

因此,我有以下结构:

class Test(object):

   def test_1(self):
      pass

   def test_2(self):
      pass

   def test_3(self):
      pass
它运行得很好,现在我添加了“场景”(正如在中推荐的):

当我运行它时,测试顺序错误,我得到:

test_1[1]  
test_1[2]  
test_2[1]   
test_2[2]  
test_3[1]  
test_3[2]
看起来不像是测试类的场景

问题:是否有按正确顺序运行的解决方案?比如:

test_1[1]
test_2[1]
test_3[1]
test_1[2]
test_2[2]
test_3[2]

py.test
以分布式方式运行测试,这意味着顺序基本上是随机的

您应该使用
-n
选项并将过程编号设置为
1
。 然后,测试应该由生成的单个进程按字母顺序运行


除此之外,我不知道你是否能做到。无论如何,根据测试的顺序进行设计通常是不好的。因此,您应该尽量不依赖它。

即将推出的pytest-2.3支持更好的(基于资源的)排序,我刚刚更新了文档中的场景示例:

您可以使用初步安装当前开发版本

pip install -i http://pypi.testrun.org -U pytest

并且应该获得带有“py.test--version”的pytest-2.3.0.dev15并能够使用它。

我认为Alex在这里指的不是分布式测试,否则我基本上同意。@Bakuriu感谢您的回答,但实际上我指的是同一过程中的测试顺序。另外关于顺序依赖性——在我看来,这是很有争议的:测试类应该是独立的,但是其中的测试方法——是我的测试步骤。我使用pytest不是为了单元测试,而是为了使用SeleniumWebDriver实现UI自动化。最新的py.test似乎不支持-n,有什么想法吗?
pip install -i http://pypi.testrun.org -U pytest