2017-02-16 28 views
1

我試圖獲得testfixtures測試與pytest傳球,但部分測試模塊的使用old pattern定義一個名爲test_suite函數,返回測試:pytest在定義時如何讓pytest尊重test_suite()?

def test_suite(): 
    return TestSuite((
     DocTestSuite(setUp=setUp, tearDown=tearDown), 
     makeSuite(LogCaptureTests), 
     )) 

當pytest嘗試收集到了這一點,它失敗並投訴:

WC1 /Users/chris/vcs/git/testfixtures/testfixtures/tests/test_logcapture.py cannot collect test class 'TestSuite' because it has a __init__ constructor 

我怎樣才能得到它來收集測試呢?

回答

0

不幸的是,我不知道你將能夠獲得pytest與舊模式進行合作。這是一個intentional design choice,任何定義__init__的類都不會被收集,我不認爲可以另外配置它​​。

更「pytesthonic」的方法是使用該選項包括文檔測試,如果你想他們,或者直接在命令行:

pytest --doctest-modules 

或者配置文件:

[pytest] 
addopts = --doctest-modules 

你仍然可以控制使用fixtures的背景下,如果你很高興堅持pytest亞軍,或者與更traditional set up and tear down如果你仍然想靈活使用其他選手如單元測試和鼻子。

+0

恐怕這些都不是文檔測試:http://pythonhosted.org/manuel/ –

+0

也許是寫一個pytest插件'manuel'的好時機。 – wim