My aim is to force the docker build to fail if the Unittests have not all passed. I'm using the following line in my DockerFile:
RUN python3 -m unittest discover test
My unit tests are in classes in the test directory. The tests are run, but a failed test does not result in a failed build. 
I know that a non-zero exit code is how to stop a build, but that does not seem to occur using this command.
Had the same problem : Fail the docker build if unittest fails in azure pipeline 
I put the below code in my build.yml file. 
errors=$(docker logs careplan-tests-1 2>&1 | grep "FAILED" -c)
        if [ $errors > 0 ]; then
          echo -e "unittest tests failed"
          docker rm apiunittest
          exit 1
        fi
Gives the output as "##[error]Bash exited with code '1'." in docker build and fails the azure pipeline.
Stop/fail docker build if tests fail