Skip to content

Update conftest.py #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 25 additions & 11 deletions software/source/server/conftest.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import os
import sys
import pytest
from source.server.i import configure_interpreter
from unittest.mock import Mock
from interpreter import OpenInterpreter
from fastapi.testclient import TestClient
from .server import app
from unittest.mock import MagicMock

# Assuming your project structure includes these modules
from source.server.server import app # Adjusted import to reflect typical project structure
from source.server.interpreter import OpenInterpreter, configure_interpreter

@pytest.fixture
@pytest.fixture(scope="module")
def client():
return TestClient(app)
"""
Pytest fixture to create a test client for the FastAPI app.
This client can be used to make requests to the API and
assert the responses.

Using 'scope="module"' to instantiate the client once per test module,
which can improve test performance.
"""
return TestClient(app)

@pytest.fixture
@pytest.fixture(scope="function")
def mock_interpreter():
interpreter = configure_interpreter(OpenInterpreter())
return interpreter
"""
Pytest fixture to create a mocked interpreter.
This mock can be used to replace the actual interpreter in tests,
allowing for isolated testing of components that depend on the interpreter.

Using 'scope="function"' to ensure a fresh mock for each test function,
which helps prevent side effects between tests.
"""
# Using MagicMock to mock the OpenInterpreter instance for more complex mocking scenarios.
interpreter = configure_interpreter(MagicMock(spec=OpenInterpreter))
return interpreter