Download tests/conftest.py from PBThuong/AI: direct link, hf CLI and curl.
- Browser
- Download file 4.04 kB
-
https://huggingface.co/spaces/PBThuong/AI/resolve/main/tests/conftest.py
- Command line
-
hf download hf://spaces/PBThuong/AI/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/PBThuong/AI/resolve/main/tests/conftest.py
4.04 kB
| """ | |
| Pytest configuration for LightRAG tests. | |
| This file provides command-line options and fixtures for test configuration. | |
| """ | |
| import pytest | |
| def pytest_configure(config): | |
| """Register custom markers for LightRAG tests.""" | |
| config.addinivalue_line( | |
| "markers", "offline: marks tests as offline (no external dependencies)" | |
| ) | |
| config.addinivalue_line( | |
| "markers", | |
| "integration: marks tests requiring external services (skipped by default)", | |
| ) | |
| config.addinivalue_line("markers", "requires_db: marks tests requiring database") | |
| config.addinivalue_line( | |
| "markers", "requires_api: marks tests requiring LightRAG API server" | |
| ) | |
| 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)", | |
| ) | |
| parser.addoption( | |
| "--run-integration", | |
| action="store_true", | |
| default=False, | |
| help="Run integration tests that require external services (database, API server, etc.)", | |
| ) | |
| def pytest_collection_modifyitems(config, items): | |
| """Modify test collection to skip integration tests by default. | |
| Integration tests are skipped unless --run-integration flag is provided. | |
| This allows running offline tests quickly without needing external services. | |
| """ | |
| if config.getoption("--run-integration"): | |
| # If --run-integration is specified, run all tests | |
| return | |
| skip_integration = pytest.mark.skip( | |
| reason="Requires external services(DB/API), use --run-integration to run" | |
| ) | |
| for item in items: | |
| if "integration" in item.keywords: | |
| item.add_marker(skip_integration) | |
| 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" | |
| 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" | |
| 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")) | |
| def run_integration_tests(request): | |
| """ | |
| Fixture to determine whether to run integration tests. | |
| Priority: CLI option > Environment variable > Default (False) | |
| """ | |
| import os | |
| # Check CLI option first | |
| if request.config.getoption("--run-integration"): | |
| return True | |
| # Fall back to environment variable | |
| return os.getenv("LIGHTRAG_RUN_INTEGRATION", "false").lower() == "true" | |