Skip to content

Commit aaca58c

Browse files
committed
added new command line in pytest to make development faster
1 parent 76bcea2 commit aaca58c

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

packages/pytest-fixtures/docker_registry.py

+27-20
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,31 @@
1414

1515

1616
@pytest.fixture(scope="session")
17-
def docker_registry() -> str:
17+
def docker_registry(keepdockerup: bool) -> str:
1818
# run the registry outside of the stack
1919
docker_client = docker.from_env()
20-
container = docker_client.containers.run(
21-
"registry:2",
22-
ports={"5000": "5000"},
23-
environment=["REGISTRY_STORAGE_DELETE_ENABLED=true"],
24-
restart_policy={"Name": "always"},
25-
detach=True,
26-
)
20+
# try to login to private registry
2721
host = "127.0.0.1"
2822
port = 5000
2923
url = "{host}:{port}".format(host=host, port=port)
30-
# Wait until we can connect
31-
assert _wait_till_registry_is_responsive(url)
24+
container = None
25+
try:
26+
docker_client.login(registry=url, username="simcore")
27+
container = docker_client.containers.list({"name":"pytest_registry"})[0]
28+
except Exception:
29+
print("Warning: docker registry is already up!")
30+
container = docker_client.containers.run(
31+
"registry:2",
32+
ports={"5000": "5000"},
33+
name="pytest_registry",
34+
environment=["REGISTRY_STORAGE_DELETE_ENABLED=true"],
35+
restart_policy={"Name": "always"},
36+
detach=True,
37+
)
38+
39+
# Wait until we can connect
40+
assert _wait_till_registry_is_responsive(url)
3241

33-
# test the registry
34-
docker_client = docker.from_env()
3542
# get the hello world example from docker hub
3643
hello_world_image = docker_client.images.pull("hello-world", "latest")
3744
# login to private registry
@@ -49,11 +56,11 @@ def docker_registry() -> str:
4956
docker_client.images.remove(image=private_image.id)
5057

5158
yield url
59+
if not keepdockerup:
60+
container.stop()
5261

53-
container.stop()
54-
55-
while docker_client.containers.list(filters={"name": container.name}):
56-
time.sleep(1)
62+
while docker_client.containers.list(filters={"name": container.name}):
63+
time.sleep(1)
5764

5865

5966
@tenacity.retry(wait=tenacity.wait_fixed(1), stop=tenacity.stop_after_delay(60))
@@ -81,9 +88,9 @@ def sleeper_service(docker_registry: str) -> Dict[str, str]:
8188
image_labels = image.labels
8289

8390
yield {
84-
json.loads(key): json.loads(value)
91+
key[len("io.simcore."):]: json.loads(value)[key[len("io.simcore."):]]
8592
for key, value in image_labels.items()
86-
if key.starts_with("io.simcore.")
93+
if key.startswith("io.simcore.")
8794
}
8895

8996

@@ -113,7 +120,7 @@ def jupyter_service(docker_registry: str) -> Dict[str, str]:
113120
image_labels = image.labels
114121

115122
yield {
116-
json.loads(key): json.loads(value)
123+
key[len("io.simcore."):]: json.loads(value)[key[len("io.simcore."):]]
117124
for key, value in image_labels.items()
118-
if key.starts_with("io.simcore.")
125+
if key.startswith("io.simcore.")
119126
}

packages/pytest-fixtures/docker_swarm.py

+15
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ def docker_swarm(docker_client: docker.client.DockerClient) -> None:
3434
assert docker_client.swarm.leave(force=True)
3535

3636

37+
def pytest_addoption(parser):
38+
parser.addoption("--keepdockerup", action="store_true", default=False, help="do not bring stack/registry down")
39+
40+
41+
@pytest.fixture(scope="session")
42+
def keepdockerup(request) -> bool:
43+
return request.config.getoption("--keepdockerup") == True
44+
45+
46+
3747
@pytest.fixture(scope="module")
3848
def docker_stack(
3949
docker_swarm,
4050
docker_client: docker.client.DockerClient,
4151
core_services_config_file: Path,
4252
ops_services_config_file: Path,
53+
keepdockerup: bool
4354
) -> Dict:
4455
stacks = {"simcore": core_services_config_file, "ops": ops_services_config_file}
4556

@@ -91,6 +102,10 @@ def _print_services(msg: str) -> None:
91102

92103
_print_services("[AFTER TEST]")
93104

105+
if keepdockerup:
106+
# skip bringing the stack down
107+
return
108+
94109
# clean up. Guarantees that all services are down before creating a new stack!
95110
#
96111
# WORKAROUND https://github.com/moby/moby/issues/30942#issue-207070098

0 commit comments

Comments
 (0)