Skip to content

Commit

Permalink
Dumping Docker output on failed test.
Browse files Browse the repository at this point in the history
Update to version 0.7.0
  • Loading branch information
butla committed Nov 17, 2017
1 parent 5622dba commit c37ac82
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ It will use the container port and localhost instead::
Changelog
=========

Version 0.7.0
-------------

* Output from containers will now be printed for failed tests.

Version 0.6.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
setup(
name='pytest-docker',
url='https://github.com/AndreLouisCaron/pytest-docker',
version='0.6.1',
version='0.7.0',
license='MIT',
maintainer='Andre Caron',
maintainer_email='[email protected]',
Expand Down
40 changes: 32 additions & 8 deletions src/pytest_docker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# -*- coding: utf-8 -*-


import attr
import functools
import os
import pytest
import re
import shlex
import subprocess
import time
import timeit

import attr
import pytest


def execute(command, success_codes=(0,)):
"""Run a shell command."""
Expand Down Expand Up @@ -68,9 +70,22 @@ def port_for(self, service, port):
if cache is not None:
return cache

output = self._docker_compose.execute(
'port %s %d' % (service, port,)
get_port = functools.partial(
self._docker_compose.execute,
'port %s %d' % (service, port,),
)

def check_if_up():
try:
get_port()
return True
except Exception as ex:
if 'No container found' in ex.args[0]:
return False
raise ex
self.wait_until_responsive(check_if_up, 5, 0.1)

output = get_port()
endpoint = output.strip()
if not endpoint:
raise ValueError(
Expand Down Expand Up @@ -114,11 +129,20 @@ class DockerComposeExecutor(object):
_compose_project_name = attr.ib()

def execute(self, subcommand):
command = '{} {}'.format(self._get_command_prefix(), subcommand)
return execute(command)

def get_up(self):
prepped_command = '{} up --build'.format(self._get_command_prefix())
subprocess.Popen(shlex.split(prepped_command))

def _get_command_prefix(self):
command = "docker-compose"
for compose_file in self._compose_files:
command += ' -f "{}"'.format(compose_file)
command += ' -p "{}" {}'.format(self._compose_project_name, subcommand)
return execute(command)
command += ' -p "{}"'.format(self._compose_project_name)
return command



@pytest.fixture(scope='session')
Expand Down Expand Up @@ -175,7 +199,7 @@ def docker_services(
return

# Spawn containers.
docker_compose.execute('up --build -d')
docker_compose.get_up()

# Let test(s) run.
yield Services(docker_compose)
Expand Down

0 comments on commit c37ac82

Please sign in to comment.