/
conftest.py
63 lines (49 loc) · 1.67 KB
/
conftest.py
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
# pylint: disable=unused-argument
from __future__ import annotations
import os
import sys
import typing as t
import subprocess
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from contextlib import ExitStack
from _pytest.main import Session
from _pytest.nodes import Item
from _pytest.config import Config
from _pytest.fixtures import FixtureRequest as _PytestFixtureRequest
class FixtureRequest(_PytestFixtureRequest):
param: str
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def pytest_collection_modifyitems(
session: Session, config: Config, items: list[Item]
) -> None:
subprocess.check_call(
["pip", "install", "-r", f"{os.path.join(PROJECT_DIR, 'requirements.txt')}"]
)
subprocess.check_call([sys.executable, f"{os.path.join(PROJECT_DIR, 'train.py')}"])
@pytest.fixture(
name="server_config_file",
params=["default.yml", "cors_enabled.yml"],
scope="session",
)
def fixture_server_config_file(request: FixtureRequest) -> str:
return os.path.join(PROJECT_DIR, "configs", request.param)
@pytest.mark.usefixtures("change_test_dir")
@pytest.fixture(scope="session")
def host(
bentoml_home: str,
deployment_mode: t.Literal["docker", "distributed", "standalone"],
server_config_file: str,
clean_context: ExitStack,
) -> t.Generator[str, None, None]:
from bentoml.testing.server import host_bento
with host_bento(
"service:svc",
config_file=server_config_file,
project_path=PROJECT_DIR,
deployment_mode=deployment_mode,
bentoml_home=bentoml_home,
clean_context=clean_context,
) as _host:
yield _host