• Add pytest command-line options • Create session-scoped fixtures • Remove hardcoded environment vars • Update test function signatures • Improve configuration priority
85 lines
2.1 KiB
Python
85 lines
2.1 KiB
Python
"""
|
|
Pytest configuration for LightRAG tests.
|
|
|
|
This file provides command-line options and fixtures for test configuration.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
"""Add custom command-line options for LightRAG tests."""
|
|
|
|
parser.addoption(
|
|
"--keep-artifacts",
|
|
action="store_true",
|
|
default=False,
|
|
help="Keep test artifacts (temporary directories and files) after test completion for inspection",
|
|
)
|
|
|
|
parser.addoption(
|
|
"--stress-test",
|
|
action="store_true",
|
|
default=False,
|
|
help="Enable stress test mode with more intensive workloads",
|
|
)
|
|
|
|
parser.addoption(
|
|
"--test-workers",
|
|
action="store",
|
|
default=3,
|
|
type=int,
|
|
help="Number of parallel workers for stress tests (default: 3)",
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def keep_test_artifacts(request):
|
|
"""
|
|
Fixture to determine whether to keep test artifacts.
|
|
|
|
Priority: CLI option > Environment variable > Default (False)
|
|
"""
|
|
import os
|
|
|
|
# Check CLI option first
|
|
if request.config.getoption("--keep-artifacts"):
|
|
return True
|
|
|
|
# Fall back to environment variable
|
|
return os.getenv("LIGHTRAG_KEEP_ARTIFACTS", "false").lower() == "true"
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def stress_test_mode(request):
|
|
"""
|
|
Fixture to determine whether stress test mode is enabled.
|
|
|
|
Priority: CLI option > Environment variable > Default (False)
|
|
"""
|
|
import os
|
|
|
|
# Check CLI option first
|
|
if request.config.getoption("--stress-test"):
|
|
return True
|
|
|
|
# Fall back to environment variable
|
|
return os.getenv("LIGHTRAG_STRESS_TEST", "false").lower() == "true"
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def parallel_workers(request):
|
|
"""
|
|
Fixture to determine the number of parallel workers for stress tests.
|
|
|
|
Priority: CLI option > Environment variable > Default (3)
|
|
"""
|
|
import os
|
|
|
|
# Check CLI option first
|
|
cli_workers = request.config.getoption("--test-workers")
|
|
if cli_workers != 3: # Non-default value provided
|
|
return cli_workers
|
|
|
|
# Fall back to environment variable
|
|
return int(os.getenv("LIGHTRAG_TEST_WORKERS", "3"))
|