为什么在 bash 脚本中运行多个 pytest 命令时出现"pytest:错误:无法识别的参数:--env=qa"



见鬼去吧,

1.

  • 我正在使用pipenv创建并激活一个安装了所有依赖项的虚拟环境
  • 所有测试都通过了,但由于以下原因,我的构建失败:
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --env=qa
inifile: /*/*/projects/<root dir>/pytest.ini
rootdir: /*/*/projects/<root dir>
  1. 元数据:{'Python':'3.8.3','Platform':'Linux-4.4.0-184-generic-x86_64-with-glibc2.17','Packages':{'ytest':'7.2.0',…}

**conftest.py**:
def pytest_addoption(parser):
parser.addoption("--env", action="store", help="Environments: qa, staging, prod")

项目目录结构

├── roster
│   ├── __init__.py
│   ├── conftest.py
│   ├── run_suite_jenkins.sh
│   ├── smoke
│   └── utils.py

**可执行bash脚本有多个这样的命令:run_suite_jenkins.sh:

pytest roster/smoke/tests/test_team.py --env=qa --alluredir allure-results 
pytest roster/smoke/tests/test_account_access.py --env=qa --alluredir allure-results
pytest roster/smoke/tests/test_brand.py --env=qa --alluredir allure-results
pytest roster/smoke/tests/test_company.py --env=qa --alluredir allure-results
.....
.....
.....

我以这种方式执行脚本:$./roster/run_suite_jenkins.sh

仅供参考。我知道我可以用这个命令运行测试,但我们不这样做是有原因的。

pytest roster/smoke/tests/ --env=qa --alluredir allure-results

任何帮助都将不胜感激。谢谢

文档解释了为什么这不起作用。它指出:

由于pytest在启动过程中如何发现插件,因此该函数只能在位于测试根目录的插件或conftest.py文件中实现。

根据您显示的存储库结构图,conftest.py文件不在tests目录的根目录中。把它移到那里,再试一次。

最新更新