1
使用鼻子測試燒瓶應用程序。我試圖用with_setup
修飾器使我的測試乾燥,而不必重複設置每個測試功能。但它似乎並沒有運行@with_setup階段。作爲文檔state我用它與測試功能,而不是測試類。一些代碼:鼻子@with_setup設置無法在測試中使用
from flask import *
from app import app
from nose.tools import eq_, assert_true
from nose import with_setup
testapp = app.test_client()
def setup():
app.config['TESTING'] = True
RUNNING_LOCAL = True
RUN_FOLDER = os.path.dirname(os.path.realpath(__file__))
fixture = {'html_hash':'aaaa'} #mocking the hash
def teardown():
app.config['TESTING'] = False
RUNNING_LOCAL = False
@with_setup(setup, teardown)
def test_scrape_wellformed_html():
#RUN_FOLDER = os.path.dirname(os.path.realpath(__file__)) #if it is here instead of inside @with_setup the code works..
#fixture = {'html_hash':'aaaa'} #mocking the hash #if it is here the code works
fixture['gush_id'] = 'current.fixed'
data = scrape_gush(fixture, RUN_FOLDER)
various assertions
例如,如果我創建@with_setup塊內的夾具字典,而不是具體的測試方法中(以及在他們每個人)我會得到一個NameError(或類似的東西)
我想我錯過了什麼,只是不知道是什麼。 感謝您的幫助!
很好的文檔都不清楚這個..讓檢查,我會更新 – alonisser
的感謝!解決了這個問題。我希望文檔在這方面更具體 – alonisser