Skip to content

Commit c37ac82

Browse files
committed
Dumping Docker output on failed test.
Update to version 0.7.0
1 parent 5622dba commit c37ac82

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ It will use the container port and localhost instead::
7979
Changelog
8080
=========
8181

82+
Version 0.7.0
83+
-------------
84+
85+
* Output from containers will now be printed for failed tests.
86+
8287
Version 0.6.0
8388
-------------
8489

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
setup(
1111
name='pytest-docker',
1212
url='https://github.com/AndreLouisCaron/pytest-docker',
13-
version='0.6.1',
13+
version='0.7.0',
1414
license='MIT',
1515
maintainer='Andre Caron',
1616
maintainer_email='[email protected]',

src/pytest_docker/__init__.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
4-
import attr
3+
import functools
54
import os
6-
import pytest
75
import re
6+
import shlex
87
import subprocess
98
import time
109
import timeit
1110

11+
import attr
12+
import pytest
13+
1214

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

71-
output = self._docker_compose.execute(
72-
'port %s %d' % (service, port,)
73+
get_port = functools.partial(
74+
self._docker_compose.execute,
75+
'port %s %d' % (service, port,),
7376
)
77+
78+
def check_if_up():
79+
try:
80+
get_port()
81+
return True
82+
except Exception as ex:
83+
if 'No container found' in ex.args[0]:
84+
return False
85+
raise ex
86+
self.wait_until_responsive(check_if_up, 5, 0.1)
87+
88+
output = get_port()
7489
endpoint = output.strip()
7590
if not endpoint:
7691
raise ValueError(
@@ -114,11 +129,20 @@ class DockerComposeExecutor(object):
114129
_compose_project_name = attr.ib()
115130

116131
def execute(self, subcommand):
132+
command = '{} {}'.format(self._get_command_prefix(), subcommand)
133+
return execute(command)
134+
135+
def get_up(self):
136+
prepped_command = '{} up --build'.format(self._get_command_prefix())
137+
subprocess.Popen(shlex.split(prepped_command))
138+
139+
def _get_command_prefix(self):
117140
command = "docker-compose"
118141
for compose_file in self._compose_files:
119142
command += ' -f "{}"'.format(compose_file)
120-
command += ' -p "{}" {}'.format(self._compose_project_name, subcommand)
121-
return execute(command)
143+
command += ' -p "{}"'.format(self._compose_project_name)
144+
return command
145+
122146

123147

124148
@pytest.fixture(scope='session')
@@ -175,7 +199,7 @@ def docker_services(
175199
return
176200

177201
# Spawn containers.
178-
docker_compose.execute('up --build -d')
202+
docker_compose.get_up()
179203

180204
# Let test(s) run.
181205
yield Services(docker_compose)

0 commit comments

Comments
 (0)