refactor: restructure tests to unit/integration and add dbt dependency - #4
Conversation
pgoell
commented
Nov 27, 2025
- Reorganize test directory structure: test/ -> tests/unit/ and tests/integration/
- Move existing tests to tests/unit/ as they use mocking
- Add dbt-core and dbt-duckdb as dev dependencies for integration testing
- Create shared conftest.py with common fixtures
- Add integration tests that run actual dbt commands
- Update pyproject.toml with pytest markers, separate test tasks
- Update ruff and ty configurations for new tests/ path
Pull Request Review: Test Restructuring and Integration TestsOverviewThis PR successfully reorganizes the test structure and adds integration tests for dbt functionality. The changes are well-executed with good separation of concerns between unit and integration tests. ✅ Strengths
🔍 Issues & Recommendations1. CI Will Run Integration Tests Without IntentionSeverity: Medium The current
Recommendation: Update the CI workflow to explicitly exclude integration tests: - name: Run tests
run: uv run pytest -m "not integration" --cov --cov-report=xmlOr add a separate integration test job that runs on a schedule or manually. 2. Missing Cleanup in dbt_project FixtureSeverity: Low The While pytest's @pytest.fixture
def dbt_project(tmp_path):
"""Copy the dbt project fixture to a temporary directory."""
project_dir = tmp_path / "dbt_project"
shutil.copytree(DBT_PROJECT_DIR, project_dir)
yield project_dir
# Cleanup is automatic via tmp_path, but could be explicit for clarityConsider adding 3. Integration Tests Could Be More ComprehensiveSeverity: Low / Suggestion Current integration tests verify basic dbt commands work, but could test:
Example: def test_dbt_run_creates_expected_output(self, dbt_project):
"""Verify dbt run actually creates the model."""
exit_code = run_dbt(
["run", "--project-dir", str(dbt_project), "--profiles-dir", str(dbt_project)]
)
assert exit_code == 0
# Could verify target/ contains compiled SQL or check DuckDB for table4. Dependency Version ConstraintsSeverity: Low Adding
5. Test Isolation: Module-Level ConstantsSeverity: Very Low In FIXTURES_DIR = Path(__file__).parent.parent / "fixtures"
DBT_PROJECT_DIR = FIXTURES_DIR / "dbt_project"This is fine, but if tests are run from different working directories, it could theoretically cause issues. Using 🔒 Security ConsiderationsNo security concerns identified. The integration tests:
🎯 Performance Considerations
📋 Test CoverageExcellent addition to test coverage. The integration tests verify:
This complements the existing unit tests which verify argument passing and error handling with mocks. 📝 Documentation & Code Style
✅ Final VerdictApprove with minor suggestions. This is a solid refactoring that improves test organization and adds valuable integration testing. The main actionable item is updating CI to exclude integration tests by default to prevent slowdowns. Recommended Actions Before Merge:
Post-Merge Considerations:
Great work on the test infrastructure improvements! 🎉 |
- Reorganize test directory structure: test/ -> tests/unit/ and tests/integration/ - Move existing tests to tests/unit/ as they use mocking - Add dbt-core and dbt-duckdb as dev dependencies for integration testing - Create shared conftest.py with common fixtures - Add integration tests that run actual dbt commands - Update pyproject.toml with pytest markers, separate test tasks - Update ruff and ty configurations for new tests/ path
1c6a707 to
cc78d20
Compare
Pull Request Review: Test Restructure and dbt IntegrationSummaryThis PR successfully restructures the test directory from ✅ StrengthsCode Quality
Architecture
Configuration
🔍 Areas for Improvement1. Integration Test Isolation (Minor)Location: The def test_dbt_version(self):
"""Test that dbt --version runs successfully."""
exit_code = run_dbt(["--version"])
assert exit_code == 0Recommendation: Consider adding a comment explaining that this test intentionally uses global dbt, or make it more isolated by setting 2. Duplicate Test Classes (Minor)Location: Both Recommendation: This is acceptable for now as it tests different code paths (direct function vs CLI entry point), but consider if all these duplicated tests are necessary. Perhaps some could be parametrized. 3. Missing Cleanup Verification (Minor)Location: The Recommendation: Add a test that verifies dbt creates expected artifacts in the right location: def test_dbt_run_creates_target_dir(self, dbt_project):
run_dbt(["run", "--project-dir", str(dbt_project), "--profiles-dir", str(dbt_project)])
assert (dbt_project / "target").exists()
# tmp_path automatically cleans up4. Example Model Could Be More Realistic (Cosmetic)Location: The current model is ultra-minimal: select 1 as id, 'test' as nameRecommendation: While this works fine, consider adding a slightly more realistic example that tests dbt's Jinja templating or ref() functions to ensure those features work in the passthrough. Example: -- This tests that dbt's Jinja engine works
select
1 as id,
'test' as name,
'{{ "compiled" }}' as templated_value5. Error Case Testing Missing (Enhancement)Location: The integration tests only verify happy paths (exit_code == 0). There are no tests for error conditions. Recommendation: Consider adding at least one test that verifies error handling: def test_dbt_run_with_invalid_project(self, tmp_path):
"""Test that dbt fails gracefully with invalid project."""
invalid_dir = tmp_path / "invalid"
invalid_dir.mkdir()
exit_code = run_dbt(["run", "--project-dir", str(invalid_dir)])
assert exit_code != 0 # Should fail, not crash🔒 SecurityNo security concerns identified. The test changes don't introduce any security vulnerabilities. ⚡ PerformanceDependency Size: Adding dbt-core and dbt-duckdb significantly increases the dependency footprint (~1500 lines in uv.lock). This is expected for integration testing but means:
Test Execution: Integration tests will be slower than unit tests due to actual dbt execution. The pytest marker system allows skipping them when needed ( 📋 Test CoverageExcellent coverage of the dbt passthrough functionality:
🎯 Recommendations Priority
✅ Final VerdictAPPROVED - This is a high-quality refactor that follows best practices. All tests pass, the code is well-organized, and the separation of concerns is clear. The additions are valuable and the migration from The minor suggestions above are enhancements rather than blockers. The PR is ready to merge as-is. Test Results: ✅ pre-commit: SUCCESS | ✅ test: SUCCESS Great work on maintaining test quality while expanding coverage! 🎉 |
…tions - Add "Before Committing" section with pre-commit command - Update test paths from test/ to tests/unit/, tests/integration/ - Add new poe tasks (test-unit, test-integration) - Document tests/fixtures/ directory
Pull Request ReviewThis PR successfully restructures the test suite with a clear separation between unit and integration tests. Overall, this is a well-executed refactoring that improves test organization and adds valuable integration coverage. ✅ StrengthsTest Organization
Integration Tests
Configuration
🔍 Issues & Recommendations1. Security: Subprocess Shell Injection Risk
|