forked from infOpen/docker-pyenv-tox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
28 lines (21 loc) · 738 Bytes
/
conftest.py
File metadata and controls
28 lines (21 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pytest
import testinfra
# Get check_output from local host
check_output = testinfra.get_host("local://").check_output
# Override the host fixture
@pytest.fixture(scope='session')
def host(request):
"""
Pytest host fixture overriden
"""
# Build image and launch container
image_id = check_output('docker build -q .').split(':')[1]
container_id = check_output("docker run -d %s", image_id)
# Manage a fixture finalizer to remove container even if exeption occurs
def finalizer():
"""
Finalizer used to remove container
"""
check_output("docker rm -f %s", container_id)
request.addfinalizer(finalizer)
yield testinfra.get_host("docker://" + container_id)