当我在 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/