简体   繁体   English

如何组织单元测试以在Python Nosetests中以特定顺序运行

[英]How can I organise my unit tests to run in a particular order in Python Nosetests

I have a set of 50 odd unit tests scheduled to be run/executed using Python Nose-tests. 我有一组50个计划使用Python鼻子测试运行/执行的奇数单元测试。

These 50+ unit tests are written in an order and such that, they leverage the output of the previous one, when run as one test suite. 这50多个单元测试是按顺序编写的,因此当作为一个测试套件运行时,它们可以利用前一个的输出。

However, Nose-tests seems to pick a order of its own and doesn't really care for the order I've configured the unit tests. 但是,鼻子测试似乎选择了自己的顺序,并不真正在意我为单元测试配置的顺序。

I've looked around for possible answers/references on stack overflow, but without success. 我到处寻找关于堆栈溢出的可能答案/参考,但是没有成功。 Can anyone point me to any existing configuration parameters or Nose-tests Flags that can be set, to have the unit tests within the test suite to be executed in a given order? 谁能指出我可以设置的任何现有配置参数或鼻子测试标志,以使测试套件中的单元测试按给定顺序执行?

Thanks in advance. 提前致谢。

Two answers, 两个答案

  • unittests should be written in such a way that you don't need the outcome of the previous test to be able to continue running the other tests... that's the whole idea about abstracting the "units" that you're testing. 单元测试应该以这样一种方式编写:您不需要先前测试的结果就能够继续运行其他测试...这就是抽象化正在测试的“单元”的全部想法。 If you really want a scenario test then write it as one test. 如果您确实需要场景测试,则将其编写为一项测试。
  • as stated by jeberle test are run alphabetically. jeberle test所述,按字母顺序运行。 if you really want you can 如果你真的想要你可以

def test_01_foo(): assert foo() def test_02_bar(): assert bar()

Nose runs the tests in a specific order: 鼻子按特定顺序运行测试:

Like py.test, nose runs functional tests in the order in which they appear in the module file. 像py.test一样,鼻子按照它们在模块文件中出现的顺序运行功能测试。 TestCase-derived tests and other test classes are run in alphabetical order. TestCase派生的测试和其他测试类以字母顺序运行。

More here: nose.readthedocs.io 更多内容请参见nas.readthedocs.io

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM