Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
testpaths = src/tests
addopts =
--disable-socket
--allow-hosts=127.0.0.1,localhost
; unix socket for Docker/testcontainers
--allow-unix-socket
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ httpx>=0.23
pytest~=7.2
pytest-asyncio>=0.21
pytest-httpbin==2.1.0
pytest-socket>=0.7.0
openai>=1.53.0,<2.0.0
freezegun>=1.2.0
ruff==0.5.3 # Should match .pre-commit-config.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
)
from dstack._internal.utils.common import get_current_datetime

pytestmark = pytest.mark.usefixtures("image_config_mock")


class TestCheckShim:
@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
get_job_provisioning_data,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")


class TestCollectMetrics:
@pytest.mark.asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
)
from dstack._internal.utils.common import get_current_datetime

pytestmark = pytest.mark.usefixtures("image_config_mock")


def get_job_provisioning_data(dockerized: bool) -> JobProvisioningData:
return JobProvisioningData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
get_run_spec,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")


async def make_run(
session: AsyncSession, status: RunStatus = RunStatus.SUBMITTED, replicas: Union[str, int] = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
get_volume_provisioning_data,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")


class TestProcessSubmittedJobs:
@pytest.mark.asyncio
Expand Down
16 changes: 16 additions & 0 deletions src/tests/_internal/server/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from pathlib import Path
from unittest.mock import Mock

import httpx
import pytest

from dstack._internal.server.main import app
from dstack._internal.server.services import encryption as encryption # import for side-effect
from dstack._internal.server.services import logs as logs_services
from dstack._internal.server.services.docker import ImageConfig, ImageConfigObject
from dstack._internal.server.testing.conf import postgres_container, session, test_db # noqa: F401


Expand All @@ -24,3 +26,17 @@ def test_log_storage(
storage = logs_services.FileLogStorage(root)
monkeypatch.setattr(logs_services, "_default_log_storage", storage)
return storage


@pytest.fixture
def image_config_mock(monkeypatch: pytest.MonkeyPatch) -> ImageConfig:
image_config = ImageConfig.parse_obj({"User": None, "Entrypoint": None, "Cmd": ["/bin/bash"]})
monkeypatch.setattr(
"dstack._internal.server.services.jobs.configurators.base._get_image_config",
Mock(return_value=image_config),
)
monkeypatch.setattr(
"dstack._internal.server.services.docker.get_image_config",
Mock(return_value=ImageConfigObject(config=image_config)),
)
return image_config
2 changes: 2 additions & 0 deletions src/tests/_internal/server/routers/test_fleets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
get_private_key_string,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")


class TestListFleets:
@pytest.mark.asyncio
Expand Down
2 changes: 2 additions & 0 deletions src/tests/_internal/server/routers/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
get_auth_headers,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")


class TestGetJobMetrics:
@pytest.mark.asyncio
Expand Down
2 changes: 2 additions & 0 deletions src/tests/_internal/server/routers/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
get_run_spec,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")

client = TestClient(app)


Expand Down
2 changes: 2 additions & 0 deletions src/tests/_internal/server/services/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
get_volume,
)

pytestmark = pytest.mark.usefixtures("image_config_mock")


async def make_run(
session: AsyncSession,
Expand Down
Loading