python - CodeBuild 仍在通过测试阶段
问题描述
我在部署我的应用程序时遇到问题,因为我的测试没有运行。它是一个简单的脚本,但代码构建仍然绕过了我的测试。我已经指定了 unittest 并将我的 unittest-buildspec 的路径放在我的应用程序的控制台中,如下所示:
-圣杯
--.圣杯
-- 构建规范
---- 构建.sh
---- unittest-buildspec.ym
-- 测试
---- test_app.py
---- 测试数据库.py
-- 应用程序.py
version: 0.2
phases:
install:
runtime-versions:
python: 3.7
commands:
- pip install -r requirements_test.txt
build:
commands:
- echo Build started on `date` ---
- pip install -r requirements_test.txt
- ./build.sh
- pytest --pep8 --flakes
artifacts:
files:
- '**/*'
base-directory: 'my-build*'
discard-paths: yes
我的 build.sh 也在同一个文件夹中
#!/bin/bash
pip install --upgrade awscli
aws --version
cd ..
pip install virtualenv
virtualenv /tmp/venv
. /tmp/venv/bin/activate
export PYTHONPATH=.
py.test tests/ || exit 1
解决方案
您共享的构建规范中有一些问题:
“安装”和“构建”阶段的缩进不正确。它们应该属于“阶段”。
在运行之前在 build.sh 上设置“+x”。
修复 buildspec.yml:
version: 0.2
phases:
install:
runtime-versions:
python: 3.7
commands:
- pip install -r requirements_test.txt
build:
commands:
- echo Build started on `date` ---
- pip install -r requirements_test.txt
- chmod +x ./build.sh
- ./build.sh
- pytest --pep8 --flakes
artifacts:
files:
- '**/*'
base-directory: 'my-build*'
discard-paths: yes
另请注意,您的“build.sh”使用“/bin/bash”解释器,虽然脚本可以工作,但从技术上讲,shell 不是“bash”,因此任何 bash 特定功能都不起作用。CodeBuild 的外壳很神秘,它会运行通常的脚本,只是不是 bash。
推荐阅读
- keystonejs - 您可以过滤反向引用字段吗?
- r - 如何在 quanteda 中对加权 dfm 的列求和?
- windows - 如何使用带有一些多行文本的命令提示符在 Windows 中创建文件?
- acumatica - Acumatica 文档报告(发票)标题不显示页面标题中的值
- javascript - 如何在数组中找到最小值,不包括第一个索引
- javascript - jQuery 替换功能没有替换有效 HTML 中的文本?
- javascript - 使用 e.target.id 禁用其他按钮
- ruby-on-rails - 读取在 S3 amazon 中上传的 CSV 文件
- javascript - 如何有条件地渲染 Angular 组件
- php - 从 ionic 发送时 api 中的未定义索引授权