mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-30 00:30:09 +00:00
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from pathlib import Path
|
|
from unittest.mock import Mock
|
|
import pytest
|
|
|
|
from haystack.testing.test_utils import set_all_seeds
|
|
|
|
set_all_seeds(0)
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_tokenizer():
|
|
"""
|
|
Tokenizes the string by splitting on spaces.
|
|
"""
|
|
tokenizer = Mock()
|
|
tokenizer.encode = lambda text: text.split()
|
|
tokenizer.decode = lambda tokens: " ".join(tokens)
|
|
return tokenizer
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_files_path():
|
|
return Path(__file__).parent / "test_files"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def request_blocker(request: pytest.FixtureRequest, monkeypatch):
|
|
"""
|
|
This fixture is applied automatically to all tests.
|
|
Those that are not marked as integration will have the requests module
|
|
monkeypatched to avoid making HTTP requests by mistake.
|
|
"""
|
|
marker = request.node.get_closest_marker("integration")
|
|
if marker is not None:
|
|
return
|
|
|
|
def urlopen_mock(self, method, url, *args, **kwargs):
|
|
raise RuntimeError(f"The test was about to {method} {self.scheme}://{self.host}{url}")
|
|
|
|
monkeypatch.setattr("urllib3.connectionpool.HTTPConnectionPool.urlopen", urlopen_mock)
|