如何使用 nose 运行 按照它们在测试脚本中出现的顺序进行测试?

How to run tests in order of their appearance in test script using nose?

我希望 运行 我的测试按顺序编写,而不是 unittest 默认情况下按字母顺序编写。

import unittest

class test2(unittest.TestCase):

   def test1(self):
      pass

   def test0(self):
      pass

class test1(unittest.TestCase):

   def testB(self):
      pass

   def testA(self):
      pass

在这个例子中,我想将unittestnosetests设置为运行测试,顺序为test1、test0、testB和testA。当我 运行 使用带有 python -m unittest -v mytestmodule 的命令行进行测试时 要么 nosetests mytestmodule.

为此我应该使用什么命令行参数?

没有这样的命令行参数。您有几个选择:

1) 重命名您的测试。在您的示例中,您所要做的就是切换 test1test0 的名称。已提出此建议 before

2) 使用 this link 处的插件。

我使用提供的 PyTest 排序插件找到了解决方案 here.

我 运行 使用 py.test MyTestModule.py -vv 进行了测试,结果如下,测试的顺序是 运行 运行ce:

MyTestModule.py::test2::test1 PASSED
MyTestModule.py::test2::test0 PASSED
MyTestModule.py::test1::testB PASSED
MyTestModule.py::test1::testA FAILED