From d84c014b2629860dd9a048f3e27666d045ab287d Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sat, 15 Oct 2022 22:43:26 +0200 Subject: [PATCH 1/2] feat: raise a more specific exception on timeout --- src/pytest_docker/plugin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pytest_docker/plugin.py b/src/pytest_docker/plugin.py index b358f59..bd1aed9 100644 --- a/src/pytest_docker/plugin.py +++ b/src/pytest_docker/plugin.py @@ -10,6 +10,16 @@ import pytest +class PytestDockerError(Exception): + """Base pytest-docker exception.""" + + +class ServiceTimeoutError(PytestDockerError): + """ + Timed out while waiting for Docker service(s). + """ + + def execute(command, success_codes=(0,)): """Run a shell command.""" try: @@ -105,7 +115,7 @@ def wait_until_responsive(self, check, timeout, pause, clock=timeit.default_time time.sleep(pause) now = clock() - raise Exception("Timeout reached while waiting on service!") + raise ServiceTimeoutError("Timeout reached while waiting on service!") def str_to_list(arg): From 117d5617ccc9c5673ca88b049e69cbb7c5795b58 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sun, 16 Oct 2022 13:13:15 +0200 Subject: [PATCH 2/2] test: adapt exception for wait_until_response failure --- tests/test_docker_services.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_docker_services.py b/tests/test_docker_services.py index 6dffe89..284eea1 100644 --- a/tests/test_docker_services.py +++ b/tests/test_docker_services.py @@ -5,6 +5,7 @@ from pytest_docker.plugin import ( DockerComposeExecutor, Services, + ServiceTimeoutError, get_docker_services, get_cleanup_command, get_setup_command, @@ -166,7 +167,7 @@ def test_wait_until_responsive_timeout(): compose_project_name="pytest123", ) services = Services(docker_compose) - with pytest.raises(Exception) as exc: + with pytest.raises(ServiceTimeoutError) as exc: print( services.wait_until_responsive( check=lambda: False, timeout=3.0, pause=1.0, clock=clock