生成狀態 最新的PyPI版本 支持的Python版本 加入討論@nose2.io

歡迎來到Nose2?

nose2 是的繼承者 nose .

它是 unittest 帶插件。

nose2 是一個新項目,不支持 nose . 見 differences 做一次徹底的總結。

Nose2的目的是擴展 unittest 使測試更好、更容易理解。

Nose2與Pytest?

nose2 可能適合或不適合您的項目。

如果您不熟悉Python測試,我們建議您也考慮 pytest 一個流行的測試框架。

快速啟動?

因為 nose2 基于UnitTest,您可以從Python標準庫的 documentation for unittest 然后使用nose2在上面增加值。

nose2 在名稱以開頭的python文件中查找測試 test 并運行它發現的每個測試函數。

下面是一個用典型的UnitTest樣式編寫的簡單測試示例:

# in test_simple.py
import unittest

class TestStrings(unittest.TestCase):
    def test_upper(self):
        self.assertEqual("spam".upper(), "SPAM")

然后您可以這樣運行此測試::

$ nose2 -v
test_upper (test_simple.TestStrings) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

然而, nose2 支持更多的測試配置,并提供更多的工具 unittest 靠自己。

例如,這個測試只練習了 nose2 的功能:

# in test_fancy.py
from nose2.tools import params

@params("Sir Bedevere", "Miss Islington", "Duck")
def test_is_knight(value):
    assert value.startswith('Sir')

然后像這樣運行:

$ nose2 -v --pretty-assert
test_fancy.test_is_knight:1
'Sir Bedevere' ... ok
test_fancy.test_is_knight:2
'Miss Islington' ... FAIL
test_fancy.test_is_knight:3
'Duck' ... FAIL

======================================================================
FAIL: test_fancy.test_is_knight:2
'Miss Islington'
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/ebs/home/sirosen/tmp/test_fancy.py", line 6, in test_is_knight
    assert value.startswith('Sir')
AssertionError

>>> assert value.startswith('Sir')

values:
    value = 'Miss Islington'
    value.startswith = <built-in method startswith of str object at 0x7f3c3172f430>
======================================================================
FAIL: test_fancy.test_is_knight:3
'Duck'
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/ebs/home/sirosen/tmp/test_fancy.py", line 6, in test_is_knight
    assert value.startswith('Sir')
AssertionError

>>> assert value.startswith('Sir')

values:
    value = 'Duck'
    value.startswith = <built-in method startswith of str object at 0x7f3c3172d490>
----------------------------------------------------------------------
Ran 3 tests in 0.001s

FAILED (failures=2)

完整文檔?

完整的文檔 nose2 可在 docs.nose2.io

版本和支持?

更改日志和版本方案?

Nose2版本有編號 0.MAJOR.MINOR 。次要版本包含錯誤修復或較小的功能。在主要版本中完成了主要功能或向后不兼容的更改。

有關所有過去版本和更改的完整說明,請參閱 changelog 。

Python版本?

Nose2支持當前支持的所有Python版本。

它還將繼續支持python2,只要它仍然可行,并且有相當大比例的nose2用戶正在使用python2。

貢獻?

如果你想做貢獻,請閱讀 contributing 指南。