diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..730daaa --- /dev/null +++ b/pytest.ini @@ -0,0 +1,22 @@ +[pytest] +testpaths = tests +python_files = test_*.py +python_classes = Test* +python_functions = test_* + +# Custom markers +markers = + slow: marks tests as slow (creates database, uses containers, etc.) + integration: marks tests that require external services + db: marks tests that require database access + +# Usage: +# pytest - Run fast tests only (default) +# pytest --run-slow - Run all tests including slow ones +# pytest -m slow --run-slow - Run only slow tests + +# Suppress common warnings +filterwarnings = + ignore::DeprecationWarning:feedparser.* + ignore::DeprecationWarning:discord.* + ignore::sqlalchemy.exc.MovedIn20Warning diff --git a/tests/conftest.py b/tests/conftest.py index 5c47f7a..fef10ad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,6 +21,39 @@ from memory.common.qdrant import initialize_collections from tests.providers.email_provider import MockEmailProvider +def pytest_addoption(parser): + """Add custom command-line options for pytest.""" + parser.addoption( + "--run-slow", + action="store_true", + default=False, + help="Run slow tests (database, containers, etc.)", + ) + + +def pytest_configure(config): + """Configure pytest with custom markers.""" + config.addinivalue_line("markers", "slow: marks tests as slow") + config.addinivalue_line("markers", "integration: marks integration tests") + config.addinivalue_line("markers", "db: marks tests that require database") + + +def pytest_collection_modifyitems(config, items): + """Auto-mark tests that use slow fixtures and skip them unless --run-slow is provided.""" + if config.getoption("--run-slow"): + # --run-slow given: don't skip slow tests + return + + skip_slow = pytest.mark.skip(reason="need --run-slow option to run") + slow_fixtures = {"test_db", "db_engine", "db_session", "qdrant"} + + for item in items: + # Check if test uses any slow fixtures + if slow_fixtures.intersection(set(getattr(item, "fixturenames", []))): + item.add_marker(pytest.mark.slow) + item.add_marker(skip_slow) + + class MockRedis: """In-memory mock of Redis for testing."""