【发布时间】:2020-09-04 09:33:57
【问题描述】:
在使用 Pipenv 和 Pytest 处理 Python FastAPI 项目时,我被要求编写一个 Pipenv 脚本来运行测试。
项目结构如下:
.
├── app
| ├── main.py
│ ├── my_package
│ │ ├── __init__.py
│ │ ├── (project folders)
│ │ └── tests
| | └── tests.py
│ └── __pycache__
└──(deployment scripts and folders, Pipfile, Dokerfile, etc)
我想从顶层结构 (./app/.../tests.py) 在 tests.py 上运行 Pytest。至少现在是这样。
按照here 的建议,我目前从顶部运行它们:
( cd app ; python -m pytest my_package/tests/tests.py )
...按预期工作。
但是,当我添加我的 Pipfile-scripts-section 时:
[scripts]
my_script = "( cd app ; python -m pytest my_package/tests/tests.py )"
...运行它:
pipenv run my_script
我得到错误:
Error: the command ( (from my_script) could not be found within PATH.
我也试过了:
[scripts]
my_script = "cd app && python -m pytest my_package/tests/tests.py"
... 返回另一个类似的错误:
Error: the command cd (from my_script) could not be found within PATH.
所以很明显我把它用作 bash 别名是错误的。 我已尝试搜索有关 [scripts] 部分如何像我一样工作的更多文档,但我没有运气(还)。
【问题讨论】:
-
如果添加
echopath = "echo %PATH%"并运行它,会打印什么?除此之外,pipenv 在我的 Linux 和 MacOS 机器上评估cd x && y到cd 'x && y',找不到目录x && y,所以这可能不会让你走得太远。 -
无法按照您的要求执行,因为我收到错误:错误:在 PATH 中找不到命令 echopath(来自 my_script_test)。但感谢您提供有关 pipenv 如何评估 cmd 的信息 :) @wjandrea 的解决方案对我有用。