test: Convert test_workspace_isolation.py to pytest style#2371
Merged
danielaskdd merged 4 commits intoHKUDS:workspace-isolationfrom Nov 17, 2025
Merged
test: Convert test_workspace_isolation.py to pytest style#2371danielaskdd merged 4 commits intoHKUDS:workspace-isolationfrom
danielaskdd merged 4 commits intoHKUDS:workspace-isolationfrom
Conversation
Why this change is needed: The test file was using a custom TestResults class for tracking test execution and results, which is not standard practice for pytest-based test suites. This makes the tests harder to integrate with CI/CD pipelines and reduces compatibility with pytest plugins and tooling. How it solves it: - Removed custom TestResults class and manual result tracking - Added @pytest.mark.asyncio decorator to all async test functions - Converted all results.add() calls to standard pytest assert statements - Added pytest fixture (setup_shared_data) for common test setup - Removed custom main() runner (pytest handles test discovery/execution) - Kept all test logic, assertions, and debugging print statements intact Impact: - All 11 test functions maintain identical behavior and coverage - Tests now follow pytest conventions and integrate with pytest ecosystem - Test output is cleaner and more informative with pytest's reporting - Easier to run selective tests using pytest's filtering options Testing: Verified by running: uv run pytest tests/test_workspace_isolation.py -v Result: All 11 tests passed in 2.41s
Why this change is needed: The mock LLM function was returning JSON format, which is incorrect for LightRAG's entity extraction. This caused "Complete delimiter can not be found" warnings and resulted in 0 entities/relations being extracted during tests. How it solves it: - Updated mock_llm_func to return correct tuple-delimited format - Format: entity<|#|>name<|#|>type<|#|>description - Format: relation<|#|>source<|#|>target<|#|>keywords<|#|>description - Added proper completion delimiter: <|COMPLETE|> - Now correctly extracts 2 entities and 1 relation Impact: - E2E test now properly validates entity/relation extraction - No more "Complete delimiter" warnings - Tests can now detect extraction-related bugs - Graph files contain actual data (2 nodes, 1 edge) instead of empty graphs Testing: All 11 tests pass in 2.42s with proper entity extraction: - Chunk 1 of 1 extracted 2 Ent + 1 Rel (previously 0 Ent + 0 Rel) - Graph files now 2564 bytes (previously 310 bytes)
…tion Add specific content assertions to detect cross-contamination between workspaces. Previously only checked that workspaces had different data, now verifies: - Each workspace contains only its own text content - Each workspace does NOT contain the other workspace's content - Cross-contamination would be immediately detected This ensures the test can find problems, not just pass. Changes: - Add assertions for "Artificial Intelligence" and "Machine Learning" in project_a - Add assertions for "Deep Learning" and "Neural Networks" in project_b - Add negative assertions to verify data leakage doesn't occur - Add detailed output messages showing what was verified Testing: - pytest tests/test_workspace_isolation.py::test_lightrag_end_to_end_workspace_isolation - Test passes with proper content isolation verified
Previous docstring mentioned only 4 scenarios but the file actually contains 11 comprehensive test cases. Updated to list all scenarios: 1. Pipeline Status Isolation 2. Lock Mechanism (Parallel/Serial) 3. Backward Compatibility 4. Multi-Workspace Concurrency 5. NamespaceLock Re-entrance Protection 6. Different Namespace Lock Isolation 7. Error Handling 8. Update Flags Workspace Isolation 9. Empty Workspace Standardization 10. JsonKVStorage Workspace Isolation 11. LightRAG End-to-End Workspace Isolation This makes the file header accurately describe its contents.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Convert workspace isolation test suite to pytest style and fix critical test issues.
Changes
1. Convert to pytest framework
TestResultsclass with standard pytest assertions@pytest.mark.asynciodecorators to async test functions2. Fix Mock LLM output format
Problem: Mock LLM returned JSON format, causing extraction failures:
Solution: Use LightRAG's tuple-delimited format:
Result: Correctly extracts 2 entities and 1 relation
3. Enhance E2E test validation
Add content-specific assertions to verify data isolation:
4. Update documentation
Update file header docstring to accurately describe all 11 test scenarios.
Testing
All 11 tests pass in 2.43s:
Impact
Related
Based on workspace-isolation branch for PR #2366.