测试失败时 Docker 构建 : returned a non-zero code: 1,

标签 docker selenium dockerfile pytest

当我在 Jenkins CI 中使用我的项目 Docker+Selenium+Pytest 运行 Docker 构建时,测试以 SUСCESS 状态结束 - 构建被推送并将结果发布到报告中,如果至少一个测试失败 - 构建失败并且结果未公布
构建错误:The command 'pytest test_page.py -s -v --alluredir=reports/allure-results' returned a non-zero code: 1也许我对 Docker 的说明配置不正确。
我的 DockerFile

FROM python:latest  as python3
FROM selenium/standalone-chrome
USER root
WORKDIR /my-projest
ADD . /my-projest
RUN pip3 install --no-cache-dir --user -r requirements.txt
RUN sudo pip3 install pytest
RUN ["pytest", "test_page.py", "-s", "-v", "--alluredir=reports/allure-results"]
和 SHELL 命令
echo "Build docker image and run container"
docker build -t $IMAGE_NAME .
docker run -d --name $CONTAINER_NAME $IMAGE_NAME

echo "Copy allure-results into Jenkins container"
rm -rf reports; mkdir reports;

docker cp $CONTAINER_NAME:my-project/reports/allure-results reports

最佳答案

可能是您的测试在断言上失败,并且失败的断言可能会抛出非 0 错误代码。
this link outlines the expected exit codes for each scenario

Exit code 0
All tests were collected and passed successfully

Exit code 1
Tests were collected and run but some of the tests failed

Exit code 2
Test execution was interrupted by the user

Exit code 3
Internal error happened while executing tests

Exit code 4
pytest command line usage error

Exit code 5
No tests were collected

关于测试失败时 Docker 构建 : returned a non-zero code: 1,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68107908/

相关文章:

docker - 如何检查 docker 容器是否已重新启动并可访问?

selenium - 使用 async/await 时无法捕获来自 Protractor 的 NoSuchAlertError

php - 如何在Docker镜像上启动服务?

javascript - Selenium 功能测试结构和实践

java - 使用 JUnit 的 Selenium

docker - hub.docker.com 的自托管替代方案?

docker - 使用 distroless 基础镜像构建多阶段 docker 镜像会导致 "no such file or directory"错误

python - 如何在Windows机器上 pip 安装Linux软件包(适用于AWS Lambda)?

Dockerfile 构建错误并写入另一个文件夹

docker - 在 Jenkins 容器中运行 docker 容器,如何设置主机的音量?