mirror of
https://github.com/mruwnik/memory.git
synced 2026-01-02 09:12:58 +01:00
Add pytest markers for fast/slow test separation
- Add --run-slow flag to optionally include slow tests - Auto-detect tests that use db_session, test_db, db_engine, or qdrant fixtures - Skip slow tests by default for faster development iteration - Usage: pytest (fast only) or pytest --run-slow (all tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
56ed7b7d8f
commit
93b77a16d6
22
pytest.ini
Normal file
22
pytest.ini
Normal file
@ -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
|
||||||
@ -21,6 +21,39 @@ from memory.common.qdrant import initialize_collections
|
|||||||
from tests.providers.email_provider import MockEmailProvider
|
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:
|
class MockRedis:
|
||||||
"""In-memory mock of Redis for testing."""
|
"""In-memory mock of Redis for testing."""
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user