我正在嘗試測驗用 pycharm 撰寫的 Django REST API 的視圖和模型,并為此安裝了 pytest。我已經撰寫了一些測驗,當我想啟動它們時,我收到以下錯誤訊息:
ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --cov=frontend --cov-report=html
然后我檢查了我是否正確安裝了 pytest,看來我已經安裝了。我同時安裝了 Python 2.7.16 和 Python 3.9.6,但正在使用 Python 3。這可能是兼容性問題還是其他問題?
我嘗試通過終端使用 py.test 和 IDE 本身開始測驗。我不斷收到同樣的錯誤訊息。
我嘗試了以下方法:
py.test:錯誤:無法識別的引數:--cov=ner_brands --cov-report=term-missing --cov-config
但我似乎得到了同樣的錯誤。
ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] [...]
_jb_pytest_runner.py: error: unrecognized arguments: --cov=frontend --cov-report=html
有誰知道我該如何解決這個問題?
提前致謝。
uj5u.com熱心網友回復:
首先,是的,Python 3.9.6 與 pytest 6.2.5 兼容,但是,您似乎缺少一些依賴項。pytest是許多不同的 Python 包之一,您似乎已經成功安裝了它,所以您已經完成了一半。
有一些不同的覆寫插件可以與 pytest 一起使用,并且需要單獨安裝。以下是 Python 和 pytest 的兩個最常見的覆寫率插件:
https://pypi.org/project/coverage/
https://pypi.org/project/pytest-cov/
第一個,coverage安裝有:
pip install coverage
第二個,pytest-cov安裝有:
pip install pytest-cov
根據您的運行命令,您似乎想要使用pytest-cov. 安裝后,您可以通過呼叫驗證 pytest 是否具有這些新選項pytest --help:
> pytest --help
...
coverage reporting with distributed testing support:
--cov=[SOURCE] Path or package name to measure during execution (multi-allowed). Use --cov= to
not do any source filtering and record everything.
--cov-reset Reset cov sources accumulated in options so far.
--cov-report=TYPE Type of report to generate: term, term-missing, annotate, html, xml (multi-
allowed). term, term-missing may be followed by ":skip-covered". annotate, html
and xml may be followed by ":DEST" where DEST specifies the output location.
Use --cov-report= to not generate any output.
--cov-config=PATH Config file for coverage. Default: .coveragerc
--no-cov-on-fail Do not report coverage if test run fails. Default: False
--no-cov Disable coverage report completely (useful for debuggers). Default: False
--cov-fail-under=MIN Fail if the total coverage is less than MIN.
...
或者,您可以使用以下方法獲得相同的結果coverage:
coverage run -m pytest
coverage html
coverage report
即使不使用pytest-cov選項,這也會為您提供覆寫率報告。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/420199.html
標籤:
上一篇:更新基于類的詳細視圖中的資料
下一篇:Django:如何創建超級用戶?
