I want run my tests in order of they are written not in alphabetical order that unittest
does by default.
我希望运行我的测试按顺序编写它们不按字母顺序编写,单元测试默认执行。
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
In this example I want to set unittest
or nosetests
to run tests in order of test1, test0, testB and testA. When I run tests using command line with python -m unittest -v mytestmodule
OR nosetests mytestmodule
.
在这个例子中,我想设置unittest或nosetests来按test1,test0,testB和testA的顺序运行测试。当我使用python -m unittest命令行运行测试-v mytestmodule或nosetests mytestmodule。
What command line argument should I use in order to do so?
我应该使用什么命令行参数来执行此操作?
2 个解决方案
#1
I found a solution for it using PyTest ordering plugin provided here.
我使用这里提供的PyTest订购插件找到了它的解决方案。
I ran tests using py.test MyTestModule.py -vv
and the results were as follows and test were run in the order of their appearance:
我使用py.test MyTestModule.py -vv运行测试,结果如下,测试按其外观顺序运行:
MyTestModule.py::test2::test1 PASSED
MyTestModule.py::test2::test0 PASSED
MyTestModule.py::test1::testB PASSED
MyTestModule.py::test1::testA FAILED
#2
There is no such command-line argument. You have a couple of options:
没有这样的命令行参数。你有几个选择:
1) Rename your tests. In your example, all you'd have to do is switch the names for test1
and test0
. This suggestion has been made before.
1)重命名您的测试。在您的示例中,您所要做的就是切换test1和test0的名称。之前已经提出过这个建议。
2) Use the plug-in at this link.
2)使用此链接上的插件。
#1
I found a solution for it using PyTest ordering plugin provided here.
我使用这里提供的PyTest订购插件找到了它的解决方案。
I ran tests using py.test MyTestModule.py -vv
and the results were as follows and test were run in the order of their appearance:
我使用py.test MyTestModule.py -vv运行测试,结果如下,测试按其外观顺序运行:
MyTestModule.py::test2::test1 PASSED
MyTestModule.py::test2::test0 PASSED
MyTestModule.py::test1::testB PASSED
MyTestModule.py::test1::testA FAILED
#2
There is no such command-line argument. You have a couple of options:
没有这样的命令行参数。你有几个选择:
1) Rename your tests. In your example, all you'd have to do is switch the names for test1
and test0
. This suggestion has been made before.
1)重命名您的测试。在您的示例中,您所要做的就是切换test1和test0的名称。之前已经提出过这个建议。
2) Use the plug-in at this link.
2)使用此链接上的插件。