Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix tests after calling fixture functions directly became an error\ #34

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions tests/test_docker_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,44 @@
import mock
import pytest

import pytest_docker
from pytest_docker import docker_ip

IP_FIXTURE_NAME = docker_ip.__name__

def test_docker_ip_native():
environ = {}
with mock.patch('os.environ', environ):
assert docker_ip() == '127.0.0.1'

def test_docker_ip_native(monkeypatch, testdir):
monkeypatch.setenv('DOCKER_HOST', '')

def test_docker_ip_remote():
environ = {
'DOCKER_HOST': 'tcp://1.2.3.4:2376',
}
with mock.patch('os.environ', environ):
assert docker_ip() == '1.2.3.4'
testdir.makepyfile("""
def test_docker_ip(docker_ip):
assert docker_ip == '127.0.0.1'
""")

result = testdir.runpytest()
result.assert_outcomes(passed=1)

@pytest.mark.parametrize('docker_host', [
'http://1.2.3.4:2376',
])
def test_docker_ip_remote_invalid(docker_host):
environ = {
'DOCKER_HOST': docker_host,
}
with mock.patch('os.environ', environ):

def test_docker_ip_remote(testdir, monkeypatch):
monkeypatch.setenv('DOCKER_HOST', 'tcp://1.2.3.4:2376')

testdir.makepyfile("""
def test_docker_ip(docker_ip):
assert docker_ip == '1.2.3.4'
""")

result = testdir.runpytest()
result.assert_outcomes(passed=1)


def test_docker_ip_remote_invalid(monkeypatch, testdir):
monkeypatch.setenv('DOCKER_HOST', 'http://1.2.3.4:2376')

testdir.makepyfile("""
def test_docker_ip_invalid(request):
with pytest.raises(ValueError) as exc:
print(docker_ip())
request.getfixturevalue(IP_FIXTURE_NAME)
assert str(exc.value) == (
'Invalid value for DOCKER_HOST: "%s".' % (docker_host,)
)
""")