亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

常用python編程軟件推薦 python編程軟件用哪個(gè)好( 二 )


[mypy]files=best_practices,testignore_missing_imports=true現(xiàn)在我們可以運(yùn)行mypy:
pipenv run mypymypy 的速查表:https://mypy.readthedocs.io/en/latest/cheatsheetpy3.html
使用pytest和pytest-cov進(jìn)行測(cè)試使用pytest編寫測(cè)試非常容易,并且消除編寫測(cè)試的阻力,意味著我們會(huì)編寫更多的測(cè)試!
pipenv install pytest pytest-cov --dev以下是pytest網(wǎng)站的一個(gè)簡單示例:
# content of test_sample.pydef inc(x): return x + 1def test_answer(): assert inc(3) == 5執(zhí)行示例:
$ pipenv run pytest=========================== test session starts ============================platform linux -- Python 3.x.y, pytest-5.x.y, py-1.x.y, pluggy-0.x.ycachedir: $PYTHON_PREFIX/.pytest_cacherootdir: $REGENDOC_TMPDIRcollected 1 itemtest_sample.py F [100%]================================= FAILURES =================================_______________________________ test_answer ________________________________ def test_answer():> assert inc(3) == 5E assert 4 == 5E + where 4 = inc(3)test_sample.py:6: AssertionError========================= 1 failed in 0.12 seconds =========================所有的測(cè)試都應(yīng)該放在 test目錄中,所以將這個(gè)配置添加到 setup.cfg:
[tool:pytest]testpaths=test我們還想檢查測(cè)試覆蓋了多少代碼 。創(chuàng)建一個(gè)新文件 .coveragerc,用來返回應(yīng)用程序代碼的覆蓋率統(tǒng)計(jì)信息,我們?cè)俅渭僭O(shè)代碼位于 best_practices模塊中:
[run]source = best_practices[report]
exclude_lines = # Have to re-enable the standard pragma pragma: no cover # Don’t complain about missing debug-only code: def __repr__ if self .debug # Don’t complain if tests don’t hit defensive assertion code: raise AssertionError raise NotImplementedError # Don’t complain if non-runnable code isn’t run: if 0 : if __name__ == .__main__.:
我們現(xiàn)在可以運(yùn)行測(cè)試并報(bào)告覆蓋率
pipenv run pytest --cov --cov-fail-under=100如果對(duì)應(yīng)用程序代碼的測(cè)試覆蓋率低于100%,則會(huì)失敗 。
pre-commit 的 Git 鉤子Git鉤子允許您在任何時(shí)候提交或推送時(shí)運(yùn)行腳本 。這就可以支持我們?cè)诿看翁峤?推送時(shí),自動(dòng)運(yùn)行所有的格式化和測(cè)試 。pre-commit可以幫助我們輕松配置這些鉤子:
在提交代碼審查之前,Git鉤子腳本可以幫助識(shí)別簡單問題 。每次提交時(shí)運(yùn)行鉤子,自動(dòng)指出代碼中的問題,例如缺少分號(hào),尾隨空格和調(diào)試語句 。在代碼審查之前指出這些問題,可以讓代碼審查者專注于代碼架構(gòu)的變化,而不是浪費(fèi)時(shí)間檢查格式問題 。
在這里,我們配置在提交Python 文件修改時(shí),執(zhí)行上述所有檢查,并且僅在推送時(shí)運(yùn)行pytest覆蓋率測(cè)試,因?yàn)楹臅r(shí)可能較長 。創(chuàng)建一個(gè)新文件 .pre-commit-config.yaml:
repos:- repo: local hooks: - id: isort name: isort stages: [commit] language: system entry: pipenv run isort types: [python] - id: black name: black stages: [commit] language: system entry: pipenv run black types: [python] - id: flake8 name: flake8 stages: [commit] language: system entry: pipenv run flake8 types: [python] exclude: setup.py - id: mypy name: mypy stages: [commit] language: system entry: pipenv run mypy types: [python] pass_filenames: false - id: pytest name: pytest stages: [commit] language: system entry: pipenv run pytest types: [python] - id: pytest-cov name: pytest stages: [push] language: system entry: pipenv run pytest --cov --cov-fail-under=100 types: [python] pass_filenames: false如果你需要跳過這些鉤子,你可以運(yùn)行 git commit–no-verify或 git push–no-verify
使用cookiecutter生成項(xiàng)目我們已經(jīng)看到了理想項(xiàng)目都使用了哪些工具,可以將其固化為一個(gè)模板,只需要1個(gè)命令 即可生成新項(xiàng)目:
pipx run cookiecutter gh:sourceryai/python-best-practices-cookiecutter填寫項(xiàng)目名稱和倉庫名稱,即可使用模板為你生成項(xiàng)目 。
要完成設(shè)置,請(qǐng)按照下列步驟操作:


以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!

「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助: