- Create and activate a Python virtual environment:
python3 -m venv .venv
. .venv/bin/activate- Install dependencies:
pip install -r requirements.txt
pip install -r test-requirements.txtUse the provided test runner script:
./run_tests.shOr run manually:
. .venv/bin/activate
PYTHONPATH=src python -m pytest tests/ -vEnvironment variables are automatically set by tests/conftest.py.
Run a specific test file:
./run_tests.sh tests/app/test_openai.py
# Expands to: PYTHONPATH=src python -m pytest tests/ -v tests/app/test_openai.pyRun a specific test function:
./run_tests.sh -k test_signature_default_algoRun tests with coverage report:
./run_tests.sh --cov=app --cov-report=htmlRun tests in quiet mode:
./run_tests.sh -qStop on first failure with short traceback:
./run_tests.sh -x --tb=shortExclude certain tests:
./run_tests.sh -k "not test_quote"Run tests matching multiple patterns:
./run_tests.sh -k "test_signature or test_stream"# Example from test_helpers.py
def setup_pynvml_mock():
mock_pynvml = MagicMock()
mock_pynvml.nvmlInit = MagicMock()
mock_pynvml.nvmlDeviceGetCount = MagicMock(return_value=1)
sys.modules['pynvml'] = mock_pynvml# Example from test_openai.py
sys.modules['app.quote.quote'] = __import__('tests.app.mock_quote', fromlist=[''])# Properly formatted cache data for signature endpoint
cache_data = json.dumps({
"text": test_data,
"signature_ecdsa": ecdsa_quote.sign(test_data),
"signing_address_ecdsa": ecdsa_quote.signing_address,
"signature_ed25519": ed25519_quote.sign(test_data),
"signing_address_ed25519": ed25519_quote.signing_address,
})The test suite is designed to run in CI environments without special hardware:
# Example GitHub Actions workflow
- name: Run tests
run: |
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
pip install -r test-requirements.txt
./run_tests.sh