diff --git a/Makefile b/Makefile index 4de93fc97..93cfda480 100644 --- a/Makefile +++ b/Makefile @@ -19,13 +19,13 @@ docs-build: jb build -W -v ./doc unit-test: - $(CMD) pytest --cov=$(PYMODULE) $(UNIT_TESTS) + $(CMD) pytest -n auto --cov=$(PYMODULE) $(UNIT_TESTS) unit-test-cov-html: - $(CMD) pytest --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report html + $(CMD) pytest -n auto --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report html unit-test-cov-xml: - $(CMD) pytest --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules + $(CMD) pytest -n auto --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules integration-test: $(CMD) pytest $(INTEGRATION_TESTS) --cov=$(PYMODULE) $(INTEGRATION_TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules diff --git a/pyproject.toml b/pyproject.toml index 423777fe7..26ebf9168 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,7 @@ dev = [ "pytest-asyncio>=0.23.5", "pytest-cov>=4.0.0", "pytest-timeout>=2.3.1", + "pytest-xdist>=3.6.1", "respx>=0.22.0", "semantic-kernel>=1.20.0", "sphinxcontrib-mermaid>=1.0.0", diff --git a/tests/unit/converter/test_azure_speech_text_converter.py b/tests/unit/converter/test_azure_speech_text_converter.py index 8b8878440..269d2ebe0 100644 --- a/tests/unit/converter/test_azure_speech_text_converter.py +++ b/tests/unit/converter/test_azure_speech_text_converter.py @@ -20,10 +20,15 @@ def is_speechsdk_installed(): @pytest.mark.skipif(not is_speechsdk_installed(), reason="Azure Speech SDK is not installed.") class TestAzureSpeechAudioToTextConverter: - @patch( - "pyrit.common.default_values.get_required_value", side_effect=lambda env_var_name, passed_value: passed_value - ) - def test_azure_speech_audio_text_converter_initialization(self, mock_get_required_value): + @pytest.fixture(autouse=True) + def setup_environment(self): + with patch( + "pyrit.common.default_values.get_required_value", + side_effect=lambda env_var_name, passed_value: passed_value or "dummy_value", + ): + yield + + def test_azure_speech_audio_text_converter_initialization(self): converter = AzureSpeechAudioToTextConverter( azure_speech_region="dummy_region", azure_speech_key="dummy_key", recognition_language="es-ES" ) diff --git a/tests/unit/converter/test_pdf_converter.py b/tests/unit/converter/test_pdf_converter.py index d47ee48d3..4a08bb7c3 100644 --- a/tests/unit/converter/test_pdf_converter.py +++ b/tests/unit/converter/test_pdf_converter.py @@ -10,11 +10,23 @@ from fpdf import FPDF from fpdf.enums import XPos, YPos from pypdf import PageObject, PdfReader +from unit.mocks import MockPromptTarget +from pyrit.memory.central_memory import CentralMemory +from pyrit.memory.duckdb_memory import DuckDBMemory from pyrit.models import DataTypeSerializer, SeedPrompt from pyrit.prompt_converter import ConverterResult, PDFConverter +@pytest.fixture +def setup_memory(): + memory = DuckDBMemory(db_path=":memory:") + CentralMemory.set_memory_instance(memory) + mock_target = MockPromptTarget() + yield mock_target + CentralMemory.set_memory_instance(None) + + @pytest.fixture def pdf_converter_no_template(): """A PDFConverter with no template path provided.""" @@ -60,7 +72,6 @@ async def test_convert_async_no_template(pdf_converter_no_template): patch.object(pdf_converter_no_template, "_generate_pdf", return_value=mock_pdf_bytes) as mock_generate, patch.object(pdf_converter_no_template, "_serialize_pdf") as mock_serialize, ): - serializer_mock = MagicMock() serializer_mock.value = "mock_url" mock_serialize.return_value = serializer_mock @@ -92,7 +103,6 @@ async def test_convert_async_with_template(pdf_converter_with_template): patch.object(pdf_converter_with_template, "_generate_pdf", return_value=mock_pdf_bytes) as mock_generate, patch.object(pdf_converter_with_template, "_serialize_pdf") as mock_serialize, ): - serializer_mock = MagicMock() serializer_mock.value = "mock_url" mock_serialize.return_value = serializer_mock @@ -370,7 +380,7 @@ async def test_empty_injection_items(mock_pdf_path): @pytest.mark.asyncio -async def test_injection_items_non_existent_page_number(mock_pdf_path): +async def test_injection_items_non_existent_page_number(mock_pdf_path, setup_memory): """ Test the PDFConverter's handling of injection items with a non-existent page number. """ @@ -405,7 +415,7 @@ async def test_injection_items_non_existent_page_number(mock_pdf_path): @pytest.mark.asyncio -async def test_non_standard_font_usage(): +async def test_non_standard_font_usage(setup_memory): """ Test the ability to use a non-standard font (Times) in PDF generation. """ @@ -434,7 +444,7 @@ async def test_non_standard_font_usage(): @pytest.mark.asyncio -async def test_injection_on_last_page(mock_pdf_path): +async def test_injection_on_last_page(mock_pdf_path, setup_memory): """ Test injecting text on the last page of a multi-page PDF """