Skip to content

Commit

Permalink
Got rid of the fallback.
Browse files Browse the repository at this point in the history
Nobody is probably using it anymore anyway.
  • Loading branch information
Michal Bultrowicz committed Oct 26, 2018
1 parent dc4902e commit 37901fb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 113 deletions.
14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ By default this plugin will try to open ``docker-compose.yml`` in your
)


You can allow this plugin to run your tests when Docker is not available.
It will use the container port and localhost instead::

@pytest.fixture(scope='session')
def docker_allow_fallback():
return True


Changelog
=========

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

* Removed the fallback method that allowed running without Docker.
It wasn't being used.

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='andre.l.caron@gmail.com',
Expand Down
28 changes: 1 addition & 27 deletions src/pytest_docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ class Services(object):
"""."""

_docker_compose = attr.ib()
_docker_allow_fallback = attr.ib(default=False)

_services = attr.ib(init=False, default=attr.Factory(dict))

def port_for(self, service, port):
"""Get the effective bind port for a service."""

# Return the container port if we run in no Docker mode.
if self._docker_allow_fallback:
return port

# Lookup in the cache.
cache = self._services.get(service, {}).get(port, None)
if cache is not None:
Expand Down Expand Up @@ -144,36 +138,16 @@ def docker_compose_project_name():
return "pytest{}".format(os.getpid())


@pytest.fixture(scope='session')
def docker_allow_fallback():
"""Return if want to run against localhost when docker is not available.
Override this fixture to return `True` if you want the ability to
run without docker.
"""
return False


@pytest.fixture(scope='session')
def docker_services(
docker_compose_file, docker_allow_fallback, docker_compose_project_name
docker_compose_file, docker_compose_project_name
):
"""Ensure all Docker-based services are up and running."""

docker_compose = DockerComposeExecutor(
docker_compose_file, docker_compose_project_name
)

# If we allowed to run without Docker, check it's presence
if docker_allow_fallback is True:
try:
execute('docker ps')
except Exception:
# Run against localhost
yield Services(docker_compose, docker_allow_fallback=True)
return

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

Expand Down
77 changes: 0 additions & 77 deletions tests/test_docker_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_docker_services():
gen = docker_services(
'docker-compose.yml',
docker_compose_project_name='pytest123',
docker_allow_fallback=False,
)
services = next(gen)
assert isinstance(services, Services)
Expand Down Expand Up @@ -82,7 +81,6 @@ def test_docker_services_unused_port():
gen = docker_services(
'docker-compose.yml',
docker_compose_project_name='pytest123',
docker_allow_fallback=False,
)
services = next(gen)
assert isinstance(services, Services)
Expand Down Expand Up @@ -138,7 +136,6 @@ def test_docker_services_failure():
gen = docker_services(
'docker-compose.yml',
docker_compose_project_name='pytest123',
docker_allow_fallback=False,
)

assert check_output.call_count == 0
Expand Down Expand Up @@ -188,77 +185,3 @@ def test_wait_until_responsive_timeout():
assert str(exc.value) == (
'Timeout reached while waiting on service!'
)


def test_get_port_docker_allow_fallback_docker_online():
with mock.patch('subprocess.check_output') as check_output:
check_output.side_effect = [b'', b'', b'0.0.0.0:32770', b'']
check_output.returncode = 0

assert check_output.call_count == 0

# The fixture is a context-manager.
gen = docker_services(
'docker-compose.yml',
docker_compose_project_name='pytest123',
docker_allow_fallback=True,
)
services = next(gen)
assert isinstance(services, Services)

assert check_output.call_count == 2

# Can request port for services.
port = services.port_for('abc', 123)
assert port == 32770

assert check_output.call_count == 3

# Next yield is last.
with pytest.raises(StopIteration):
print(next(gen))

assert check_output.call_count == 4

assert check_output.call_args_list == [
mock.call(
'docker ps',
shell=True, stderr=subprocess.STDOUT,
),
mock.call(
'docker-compose -f "docker-compose.yml" -p "pytest123" '
'up --build -d',
shell=True, stderr=subprocess.STDOUT,
),
mock.call(
'docker-compose -f "docker-compose.yml" -p "pytest123" '
'port abc 123',
shell=True, stderr=subprocess.STDOUT,
),
mock.call(
'docker-compose -f "docker-compose.yml" -p "pytest123" down -v',
shell=True, stderr=subprocess.STDOUT,
),
]


def test_get_port_docker_allow_fallback_docker_offline():
with mock.patch('subprocess.check_output') as check_output:
check_output.side_effect = [
subprocess.CalledProcessError(
1, 'the command', b'the output',
),
]
check_output.returncode = 1

gen = docker_services(
'docker-compose.yml',
docker_compose_project_name='pytest123',
docker_allow_fallback=True,
)
services = next(gen)
assert services.port_for('abc', 123) == 123

# Next yield is last.
with pytest.raises(StopIteration):
print(next(gen))

0 comments on commit 37901fb

Please sign in to comment.