You can use the when keyword to control the condition. If your previous test step fails then you can find the status. Use that status in the when condition and tell if it fails. remove the container. You can run the below command in your playbook with the command module.
docker rm -f $(docker ps -a -q)