-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathconftest.py
More file actions
68 lines (52 loc) · 1.86 KB
/
conftest.py
File metadata and controls
68 lines (52 loc) · 1.86 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# pylint: disable=import-error, invalid-name
""" Fixtures for tests """
import os
from pytest import fixture
from testcontainers.compose import DockerCompose
from qiskit_serverless import ServerlessClient, QiskitFunction
from qiskit_serverless.core.clients.local_client import LocalClient
resources_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "source_files"
)
@fixture(scope="module", params=["serverless", "local"])
def base_client(request):
"""Fixture for testing files with every client."""
if request.param == "serverless":
[compose, serverless] = set_up_serverless_client()
yield serverless
compose.stop()
else:
yield LocalClient()
@fixture(scope="module")
def local_client():
"""Fixture for testing files with local client."""
return LocalClient()
def set_up_serverless_client():
"""Auxiliar fixture function to create a serverless client"""
compose = DockerCompose(
resources_path,
compose_file_name="../../../docker-compose-dev.yaml",
pull=True,
)
compose.start()
connection_url = "http://localhost:8000"
compose.wait_for(f"{connection_url}/backoffice")
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", connection_url),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
# Initialize serverless folder for current user
function = QiskitFunction(
title="hello-world",
entrypoint="hello_world.py",
working_dir=resources_path,
)
serverless.upload(function)
return [compose, serverless]
@fixture(scope="module")
def serverless_client():
"""Fixture for testing files with serverless client."""
[compose, serverless] = set_up_serverless_client()
yield serverless
compose.stop()