From 912b8e047203e7216cb2b99294d16860be729f9c Mon Sep 17 00:00:00 2001 From: Kartik Sarangmath Date: Wed, 9 Jul 2025 14:03:38 -0700 Subject: [PATCH] reduces deps --- Makefile | 35 ++++++++++++++---------------- conftest.py | 24 +++++++++++++++++++++ pyproject.toml | 41 +++++++++++++++++++++++++++-------- scripts/run_all_tests.sh | 46 +++++++--------------------------------- 4 files changed, 80 insertions(+), 66 deletions(-) create mode 100644 conftest.py diff --git a/Makefile b/Makefile index b994d6c..d427402 100644 --- a/Makefile +++ b/Makefile @@ -37,26 +37,23 @@ ruff-check: ruff-format-check: ruff format --check . -# Run tests +# Run all tests test: - ./scripts/run_all_tests.sh + pytest -# Run SDK tests -test-sdk: - cd sdk/python && pytest tests -v +# Run unit tests only (skip integration) +test-unit: + pytest -m "not integration" -# Run backend tests -test-backend: - cd backend && pytest tests -v || echo "No backend tests yet" - -# Run server tests -test-servers: - cd servers && pytest tests -v || echo "No server tests yet" - -# Run all tests with coverage -test-coverage: - cd sdk/python && pytest tests --cov=omnara --cov-report=term-missing - -# Run integration tests with PostgreSQL (requires Docker) +# Run integration tests only test-integration: - pytest servers/tests/test_integration.py -v -m integration + pytest -m integration + +# Run tests with coverage +test-coverage: + pytest --cov=backend --cov=servers --cov=omnara --cov=shared --cov-report=term-missing + +# Run specific test file or pattern +# Usage: make test-k ARGS="test_auth" +test-k: + pytest -k "$(ARGS)" diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..52c9459 --- /dev/null +++ b/conftest.py @@ -0,0 +1,24 @@ +"""Root-level pytest configuration and shared fixtures.""" + +import os +import pytest + +# Set test environment +os.environ["ENVIRONMENT"] = "test" +os.environ["SENTRY_DSN"] = "" + + +@pytest.fixture(scope="session", autouse=True) +def test_environment(): + """Ensure test environment is set.""" + original_env = os.environ.copy() + + # Set test environment variables + os.environ["ENVIRONMENT"] = "test" + os.environ["SENTRY_DSN"] = "" + + yield + + # Restore original environment + os.environ.clear() + os.environ.update(original_env) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 2adf328..f401e90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,16 +21,12 @@ classifiers = [ "Programming Language :: Python :: 3.12", ] dependencies = [ - "fastmcp==2.9.2", - "sqlalchemy==2.0.23", - "psycopg2-binary==2.9.9", - "pydantic>=2.5.2", - "pydantic-settings>=2.6.1", - "python-dotenv>=1.1.0", - # SDK dependencies + # Core SDK dependencies "requests>=2.25.0", "urllib3>=1.26.0", "aiohttp>=3.8.0", + # MCP server dependency + "fastmcp==2.9.2", ] [project.urls] @@ -42,11 +38,38 @@ Issues = "https://github.com/omnara-ai/omnara/issues" omnara = "servers.mcp_server.stdio_server:main" [tool.setuptools.packages.find] -include = ["omnara*", "servers", "servers.mcp_server"] +include = ["omnara*", "servers.mcp_server*", "servers.shared*"] + [tool.pytest.ini_options] +# Test discovery +testpaths = ["backend/tests", "servers/tests", "tests"] +python_files = ["test_*.py"] + +# Markers markers = [ "integration: marks tests as integration tests (deselect with '-m \"not integration\"')", ] + +# Asyncio support asyncio_mode = "auto" -asyncio_default_fixture_loop_scope = "function" \ No newline at end of file + +# Basic options +addopts = [ + "-v", + "--strict-markers", + "--tb=short", +] + +[tool.coverage.run] +source = ["backend", "servers", "omnara", "shared"] +omit = [ + "*/tests/*", + "*/__pycache__/*", + "*/migrations/*", + "*/alembic/*", +] + +[tool.coverage.report] +skip_covered = true +show_missing = true \ No newline at end of file diff --git a/scripts/run_all_tests.sh b/scripts/run_all_tests.sh index 0dfc936..5ae9dce 100755 --- a/scripts/run_all_tests.sh +++ b/scripts/run_all_tests.sh @@ -1,45 +1,15 @@ #!/bin/bash -# Run all Python tests across the monorepo +# Run all Python tests set -e -# Set test environment to disable Sentry -export ENVIRONMENT=test -export SENTRY_DSN="" +echo "🧪 Running Python Tests" +echo "======================" -echo "🧪 Running All Python Tests" -echo "===========================" +# Change to root directory +cd "$(dirname "$0")/.." -# Store the root directory (parent of scripts dir) -ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +# Run pytest - configuration is in pytest.ini and pyproject.toml +pytest "$@" -# Function to run tests in a directory if they exist -run_component_tests() { - local component=$1 - local test_dir="$ROOT_DIR/$component" - - if [ -d "$test_dir" ]; then - echo -e "\n📦 Testing $component..." - cd "$ROOT_DIR" # Stay in root directory - - # Run pytest if tests directory exists - if [ -d "$test_dir/tests" ]; then - PYTHONPATH="$ROOT_DIR:$PYTHONPATH" pytest "$component/tests" -v - else - echo " No tests found in $component" - fi - fi -} - -# Run tests for each component -run_component_tests "backend" -run_component_tests "servers" - -# Run root-level integration tests if they exist -if [ -d "$ROOT_DIR/tests" ]; then - echo -e "\n🌐 Running integration tests..." - cd "$ROOT_DIR" - pytest tests -v -fi - -echo -e "\n✅ All tests completed!" \ No newline at end of file +echo -e "\n✅ Tests completed!" \ No newline at end of file