歡迎來到Nose2?
nose2
是的繼承者 nose
.
它是 unittest
帶插件。
nose2
是一個新項目,不支持 nose
. 見 differences 做一次徹底的總結。
Nose2的目的是擴展 unittest
使測試更好、更容易理解。
快速啟動?
因為 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
版本和支持?
貢獻?
如果你想做貢獻,請閱讀 contributing 指南。
用戶指南?
- 開始使用Nose2
- 使用 nose2
- 配置nose2
- 差異:nose2與nose與unittest2
- nose2插件
- 工具和助手
- Changelog
- 0.10.0(2020-01-27)
- 0.9.2(2020-02-02)
- 0.9.1(2019-04-02)
- 0.9.0(2019-03-17)
- 0.8.0(2018-07-31)
- 0.7.4(2018-02-17)
- 0.7.3(2017/12/13)
- 0.7.2(2017/11/14)
- 0.7.0(2017-11-05)
- 0.6.5(2016-06-29)
- 0.6.4(2016-03-15)
- 0.6.3(2016-03-01)
- 0.6.2(2016-02-24)
- 0.6.1(2016-02-23)
- 0.6.0(2016-02-21)
- 0.5.0(2014-09-14)
- 0.4.7(2013-08-13)
- 0.4.6(2013-04-07)
- 0.4.5(2012-12-16)
- 0.4.4(2012-11-26)
- 0.4.3(2012-11-21)
- 0.4.2(2012-11-19)
- 0.4.1(2012-06-18)
- 0.3(2012-04-15)
- 0.2(2012-02-06)
- 0.1(2012-01-19)
插件開發人員指南?
- 正在寫入插件
- 記錄插件
- 事件引用
CommandLineArgsEvent
CreateTestsEvent
CreatedTestSuiteEvent
DescribeTestEvent
Event
GetTestCaseNamesEvent
HandleFileEvent
LoadFromModuleEvent
LoadFromNameEvent
LoadFromNamesEvent
LoadFromTestCaseEvent
MatchPathEvent
ModuleSuiteEvent
OutcomeDetailEvent
PluginsLoadedEvent
ReportSummaryEvent
ReportTestEvent
ResultCreatedEvent
ResultStopEvent
ResultSuccessEvent
RunnerCreatedEvent
StartLayerSetupEvent
StartLayerSetupTestEvent
StartLayerTeardownEvent
StartLayerTeardownTestEvent
StartTestEvent
StartTestRunEvent
StopLayerSetupEvent
StopLayerSetupTestEvent
StopLayerTeardownEvent
StopLayerTeardownTestEvent
StopTestEvent
StopTestRunEvent
TestOutcomeEvent
UserInteractionEvent
- 鉤參考
- 會話引用
- 插件類引用