第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Pytest:無(wú)法讓 Flask 應(yīng)用程序在測(cè)試中運(yùn)行

Pytest:無(wú)法讓 Flask 應(yīng)用程序在測(cè)試中運(yùn)行

慕森王 2021-11-02 17:04:00
我正在嘗試研究如何使用pytest來(lái)測(cè)試最基本的 Flask 應(yīng)用程序。(我在 Windows 10 上)。這是應(yīng)用程序代碼 myapp.py:from flask import Flaskapi = Flask(__name__)@api.route('/', methods=['GET'])def index():    return 'Index Page'當(dāng)我在瀏覽器中訪問(wèn)http://127.0.0.1:5000/時(shí),或者當(dāng)我使用 curl 向該 URL 發(fā)出 GET 請(qǐng)求時(shí),它工作正常,我看到“索引頁(yè)面”響應(yīng)文本。然后我設(shè)置了一個(gè)基本的測(cè)試腳本,test_app.py:import pytestfrom flask import Flaskdef test_assert():    assert Truedef test_home_page(client):  response = client.get('/')  assert response.status_code == 200@pytest.fixturedef client():  flask_app = Flask(__name__)   client = flask_app.test_client()  return client我添加了第一個(gè)簡(jiǎn)單的 test_assert() 函數(shù)只是為了確保 pytest 正常工作(我是 python 新手)?,F(xiàn)在,當(dāng)我運(yùn)行 pytest (>pytest -v) 時(shí),第一個(gè)(瑣碎的)測(cè)試通過(guò),但 test_home_page() 測(cè)試失敗。該應(yīng)用程序在通過(guò) pytest 運(yùn)行時(shí)返回狀態(tài)代碼 404。collected 2 itemstest_app.py::test_assert PASSED                                                                                  [ 50%]test_app.py::test_home_page FAILED                                                                               [100%]====================================================== FAILURES =======================================================___________________________________________________ test_home_page ____________________________________________________client = <FlaskClient <Flask 'test_app'>>    def test_home_page(client):      response = client.get('/')>     assert response.status_code == 200E     assert 404 == 200E       -404E       +200test_app.py:10: AssertionError========================================= 1 failed, 1 passed in 0.28 seconds ====我花了幾天時(shí)間閱讀試圖確定為什么 pytest 在這個(gè)簡(jiǎn)單的例子中失敗——響應(yīng)應(yīng)該是 200,但它一直給出 404。誰(shuí)能看到我做錯(cuò)了什么或者為什么這不起作用?謝謝。
查看完整描述

1 回答

?
慕容森

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊

嘗試這個(gè):


from YOUR_MODULE import api 


def test_assert():

    assert True


def test_home_page(client):

  response = client.get('/')

  assert response.status_code == 200


@pytest.fixture

def client():

  client = api.test_client()

  return client


查看完整回答
反對(duì) 回復(fù) 2021-11-02
  • 1 回答
  • 0 關(guān)注
  • 177 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)