| @@ -3,15 +3,12 @@ from collections.abc import Callable | |||
| import pytest | |||
| # import monkeypatch | |||
| from _pytest.monkeypatch import MonkeyPatch | |||
| from core.plugin.impl.model import PluginModelClient | |||
| from tests.integration_tests.model_runtime.__mock.plugin_model import MockModelClass | |||
| def mock_plugin_daemon( | |||
| monkeypatch: MonkeyPatch, | |||
| monkeypatch: pytest.MonkeyPatch, | |||
| ) -> Callable[[], None]: | |||
| """ | |||
| mock openai module | |||
| @@ -34,7 +31,7 @@ MOCK = os.getenv("MOCK_SWITCH", "false").lower() == "true" | |||
| @pytest.fixture | |||
| def setup_model_mock(monkeypatch): | |||
| def setup_model_mock(monkeypatch: pytest.MonkeyPatch): | |||
| if MOCK: | |||
| unpatch = mock_plugin_daemon(monkeypatch) | |||
| @@ -3,7 +3,6 @@ from typing import Literal | |||
| import pytest | |||
| import requests | |||
| from _pytest.monkeypatch import MonkeyPatch | |||
| from core.plugin.entities.plugin_daemon import PluginDaemonBasicResponse | |||
| from core.tools.entities.common_entities import I18nObject | |||
| @@ -53,7 +52,7 @@ MOCK_SWITCH = os.getenv("MOCK_SWITCH", "false").lower() == "true" | |||
| @pytest.fixture | |||
| def setup_http_mock(request, monkeypatch: MonkeyPatch): | |||
| def setup_http_mock(request, monkeypatch: pytest.MonkeyPatch): | |||
| if MOCK_SWITCH: | |||
| monkeypatch.setattr(requests, "request", MockedHttp.requests_request) | |||
| @@ -3,7 +3,6 @@ from typing import Literal | |||
| import httpx | |||
| import pytest | |||
| from _pytest.monkeypatch import MonkeyPatch | |||
| from core.helper import ssrf_proxy | |||
| @@ -30,7 +29,7 @@ class MockedHttp: | |||
| @pytest.fixture | |||
| def setup_http_mock(request, monkeypatch: MonkeyPatch): | |||
| def setup_http_mock(request, monkeypatch: pytest.MonkeyPatch): | |||
| monkeypatch.setattr(ssrf_proxy, "make_request", MockedHttp.httpx_request) | |||
| yield | |||
| monkeypatch.undo() | |||
| @@ -8,7 +8,7 @@ from yarl import URL | |||
| from configs.app_config import DifyConfig | |||
| def test_dify_config(monkeypatch): | |||
| def test_dify_config(monkeypatch: pytest.MonkeyPatch): | |||
| # clear system environment variables | |||
| os.environ.clear() | |||
| @@ -48,7 +48,7 @@ def test_dify_config(monkeypatch): | |||
| # NOTE: If there is a `.env` file in your Workspace, this test might not succeed as expected. | |||
| # This is due to `pymilvus` loading all the variables from the `.env` file into `os.environ`. | |||
| def test_flask_configs(monkeypatch): | |||
| def test_flask_configs(monkeypatch: pytest.MonkeyPatch): | |||
| flask_app = Flask("app") | |||
| # clear system environment variables | |||
| os.environ.clear() | |||
| @@ -101,7 +101,7 @@ def test_flask_configs(monkeypatch): | |||
| assert str(URL(str(config["CODE_EXECUTION_ENDPOINT"])) / "v1") == "http://127.0.0.1:8194/v1" | |||
| def test_inner_api_config_exist(monkeypatch): | |||
| def test_inner_api_config_exist(monkeypatch: pytest.MonkeyPatch): | |||
| # Set environment variables using monkeypatch | |||
| monkeypatch.setenv("CONSOLE_API_URL", "https://example.com") | |||
| monkeypatch.setenv("CONSOLE_WEB_URL", "https://example.com") | |||
| @@ -119,7 +119,7 @@ def test_inner_api_config_exist(monkeypatch): | |||
| assert len(config.INNER_API_KEY) > 0 | |||
| def test_db_extras_options_merging(monkeypatch): | |||
| def test_db_extras_options_merging(monkeypatch: pytest.MonkeyPatch): | |||
| """Test that DB_EXTRAS options are properly merged with default timezone setting""" | |||
| # Set environment variables | |||
| monkeypatch.setenv("DB_USERNAME", "postgres") | |||
| @@ -164,7 +164,13 @@ def test_db_extras_options_merging(monkeypatch): | |||
| ], | |||
| ) | |||
| def test_celery_broker_url_with_special_chars_password( | |||
| monkeypatch, broker_url, expected_host, expected_port, expected_username, expected_password, expected_db | |||
| monkeypatch: pytest.MonkeyPatch, | |||
| broker_url, | |||
| expected_host, | |||
| expected_port, | |||
| expected_username, | |||
| expected_password, | |||
| expected_db, | |||
| ): | |||
| """Test that CELERY_BROKER_URL with various formats are handled correctly.""" | |||
| from kombu.utils.url import parse_url | |||
| @@ -43,28 +43,28 @@ def _get_test_app(): | |||
| @pytest.fixture | |||
| def mock_request_receiver(monkeypatch) -> mock.Mock: | |||
| def mock_request_receiver(monkeypatch: pytest.MonkeyPatch) -> mock.Mock: | |||
| mock_log_request_started = mock.Mock() | |||
| monkeypatch.setattr(ext_request_logging, "_log_request_started", mock_log_request_started) | |||
| return mock_log_request_started | |||
| @pytest.fixture | |||
| def mock_response_receiver(monkeypatch) -> mock.Mock: | |||
| def mock_response_receiver(monkeypatch: pytest.MonkeyPatch) -> mock.Mock: | |||
| mock_log_request_finished = mock.Mock() | |||
| monkeypatch.setattr(ext_request_logging, "_log_request_finished", mock_log_request_finished) | |||
| return mock_log_request_finished | |||
| @pytest.fixture | |||
| def mock_logger(monkeypatch) -> logging.Logger: | |||
| def mock_logger(monkeypatch: pytest.MonkeyPatch) -> logging.Logger: | |||
| _logger = mock.MagicMock(spec=logging.Logger) | |||
| monkeypatch.setattr(ext_request_logging, "logger", _logger) | |||
| return _logger | |||
| @pytest.fixture | |||
| def enable_request_logging(monkeypatch): | |||
| def enable_request_logging(monkeypatch: pytest.MonkeyPatch): | |||
| monkeypatch.setattr(dify_config, "ENABLE_REQUEST_LOGGING", True) | |||
| @@ -1,9 +1,11 @@ | |||
| import datetime | |||
| import pytest | |||
| from libs.datetime_utils import naive_utc_now | |||
| def test_naive_utc_now(monkeypatch): | |||
| def test_naive_utc_now(monkeypatch: pytest.MonkeyPatch): | |||
| tz_aware_utc_now = datetime.datetime.now(tz=datetime.UTC) | |||
| def _now_func(tz: datetime.timezone | None) -> datetime.datetime: | |||
| @@ -143,7 +143,7 @@ def test_uuidv7_with_custom_timestamp(): | |||
| assert extracted_timestamp == custom_timestamp # Exact match for integer milliseconds | |||
| def test_uuidv7_with_none_timestamp(monkeypatch): | |||
| def test_uuidv7_with_none_timestamp(monkeypatch: pytest.MonkeyPatch): | |||
| """Test UUID generation with None timestamp uses current time.""" | |||
| mock_time = 1609459200 | |||
| mock_time_func = mock.Mock(return_value=mock_time) | |||