pytest我正在為我的 django 專案撰寫一些測驗用例。我.ini在根目錄中創建了一個檔案,如下所示:
python_files =
tests.py
test_*.py
*_tests.py
*_test.py
norecursedirs =
devops
docs
media
settings
common
templates
addopts =
--maxfail=9999
--showlocals
--color=yes
--runxfail
--strict-markers
--durations=30
-r a
; --reuse-db
--no-migrations
--pdbcls=IPython.terminal.debugger:TerminalPdb
并在主目錄中創建了一個檔案夾/devops,并在一個名為的 bash 檔案中backend_tests.sh:
#!/usr/bin/env bash
options =("--cov")
options =("--disable-warnings")
echo "launch pytest ${options[@]}"
poetry run pytest "${options[@]}"
if [[ $? == 1 ]]; then exit 1; fi
當我運行devops/backend_tests.sh它時顯示,收集了 0 個專案,但是當我移動backend_tests.sh到主目錄并運行它時,./backend_tests.sh它顯示收集了 5 個專案(這意味著加載測驗用例。
uj5u.com熱心網友回復:
如果沒有給 引數pytest,它會從當前路徑遞回地發現測驗。所以如果你想使用相同的命令,你可以改變它的執行路徑:
pushd <test_path>
poetry run pytest
popd
您還可以在命令列上提供測驗或測驗路徑,因此最短的方法就是:
poetry run pytest <test_path>
(<test_path>在你的情況下可能只是..)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/483478.html
標籤:重击 目录 pytest pytest-django
