【发布时间】:2022-05-30 04:24:21
【问题描述】:
我正在为我的 django 项目使用 pytest 编写几个测试用例。我在根目录中创建了一个.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 和一个名为 backend_tests.sh 的 bash 文件,如:
#!/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 个项目(这意味着加载测试用例。
-
这是意料之中的——
pytest使用 Python 路径。您可以从脚本的根路径运行pytest,也可以将根路径添加到 Python 路径。 -
啊,谢谢它现在可以工作了。如果你写作为答案我会接受
标签: bash directory pytest pytest-django