Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build: returned a non-zero code: 1, when test is failed

When I run Docker build with my project Docker+Selenium+Pytest in Jenkins CI with tests that end with the SUСCESS status - the build is pushed and the results are published to reports, and if at least one test fails - the build fails and the results are not published

Build Error: The command 'pytest test_page.py -s -v --alluredir=reports/allure-results' returned a non-zero code: 1

Maybe my instructions for Docker are incorrectly configured. My 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"]

and SHELL Command

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
like image 964
juran Avatar asked May 10 '26 09:05

juran


1 Answers

It may be that your tests are failing on an assertion and that failed assertion may be throwing the non 0 error code.

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
like image 121
richardsefton Avatar answered May 12 '26 12:05

richardsefton