I have developped a class that uses the docker library with
self.client = docker.from_env(timeout=5, version="auto")
and as example:
def run_container_in_background(self,application,branch,name_container,mount_dir):
container =self.client.containers.run(image,command"bash",detach=True,name=name_container)
I need to make a unit test for this method so i need to mock the docker server. So does anyoe have an idea how to mock it using python?
When I try to mock "self.client = docker.from_env(timeout=5, version="auto")"
self = <docker.api.client.APIClient object at 0x0EE644D0>
def _retrieve_server_version(self):
try:
return self.version(api_version=False)["ApiVersion"]
except KeyError:
raise DockerException(
'Invalid response from docker daemon: key "ApiVersion"'
' is missing.'
)
except Exception as e:
raise DockerException('Error while fetching server API version:
{0}'.format(e))
E docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'Le fichier spécifié est introuvable.')
PS: the docker daemon is deactivate to reproduce the same issue i want to solve. Is there any way to solve the mocking problem to fix this issue?