From 424f25b74f1c7c2efc02266bb9b737b27069c71a Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 15:34:39 -0800 Subject: [PATCH 1/9] test: add comprehensive tests for catalog extra fields handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add test suite to verify that the Metadata class correctly handles extra fields from dbt, preventing job failures when dbt adds new fields. Tests cover: - Extra fields are accepted without validation errors - Extra fields are stored in __pydantic_extra__ - model_dump() includes extra fields - Specific case of invocation_started_at field - Various combinations of known and unknown fields 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- tests/conftest.py | 8 +++ tests/vendor/__init__.py | 0 tests/vendor/conftest.py | 7 ++ tests/vendor/test_catalog_v1.py | 113 ++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/vendor/__init__.py create mode 100644 tests/vendor/conftest.py create mode 100644 tests/vendor/test_catalog_v1.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..bf0fd0c0 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,8 @@ +"""Root pytest configuration.""" +import sys +from pathlib import Path + +# Add src directory to Python path for all tests +src_path = Path(__file__).parent.parent / "src" +if str(src_path) not in sys.path: + sys.path.insert(0, str(src_path)) diff --git a/tests/vendor/__init__.py b/tests/vendor/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/vendor/conftest.py b/tests/vendor/conftest.py new file mode 100644 index 00000000..42d2df08 --- /dev/null +++ b/tests/vendor/conftest.py @@ -0,0 +1,7 @@ +"""Pytest configuration for vendor tests.""" +import sys +from pathlib import Path + +# Add src directory to Python path +src_path = Path(__file__).parent.parent.parent / "src" +sys.path.insert(0, str(src_path)) diff --git a/tests/vendor/test_catalog_v1.py b/tests/vendor/test_catalog_v1.py new file mode 100644 index 00000000..084f955e --- /dev/null +++ b/tests/vendor/test_catalog_v1.py @@ -0,0 +1,113 @@ +"""Tests for catalog v1 parser, specifically testing extra fields handling.""" +import pytest + +from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import Metadata + + +class TestMetadataExtraFields: + """Test that Metadata class accepts extra fields from dbt.""" + + def test_metadata_accepts_extra_fields(self): + """Test that metadata accepts fields not explicitly defined in the model.""" + # Test with a new field that dbt might add in the future + data = { + "dbt_schema_version": "https://schemas.getdbt.com/dbt/catalog/v1.json", + "dbt_version": "1.9.0", + "generated_at": "2025-11-05T10:00:00Z", + "invocation_id": "test-invocation-123", + "invocation_started_at": "2025-11-05T09:59:00Z", # New field + "new_future_field": "some_value", # Another potential future field + } + + # This should not raise a validation error + metadata = Metadata(**data) + + # Verify that known fields are accessible normally + assert metadata.dbt_schema_version == "https://schemas.getdbt.com/dbt/catalog/v1.json" + assert metadata.dbt_version == "1.9.0" + assert metadata.generated_at == "2025-11-05T10:00:00Z" + assert metadata.invocation_id == "test-invocation-123" + + def test_metadata_extra_fields_in_pydantic_extra(self): + """Test that extra fields are stored in __pydantic_extra__.""" + data = { + "dbt_version": "1.9.0", + "invocation_started_at": "2025-11-05T09:59:00Z", + "new_field_1": "value1", + "new_field_2": 123, + } + + metadata = Metadata(**data) + + # Extra fields should be stored in __pydantic_extra__ + assert metadata.__pydantic_extra__ is not None + assert "invocation_started_at" in metadata.__pydantic_extra__ + assert "new_field_1" in metadata.__pydantic_extra__ + assert "new_field_2" in metadata.__pydantic_extra__ + assert metadata.__pydantic_extra__["invocation_started_at"] == "2025-11-05T09:59:00Z" + assert metadata.__pydantic_extra__["new_field_1"] == "value1" + assert metadata.__pydantic_extra__["new_field_2"] == 123 + + def test_metadata_model_dump_includes_extra_fields(self): + """Test that model_dump() includes extra fields.""" + data = { + "dbt_version": "1.9.0", + "invocation_id": "test-123", + "invocation_started_at": "2025-11-05T09:59:00Z", + "future_field": "future_value", + } + + metadata = Metadata(**data) + dumped = metadata.model_dump() + + # All fields including extra should be in the dump + assert dumped["dbt_version"] == "1.9.0" + assert dumped["invocation_id"] == "test-123" + assert dumped["invocation_started_at"] == "2025-11-05T09:59:00Z" + assert dumped["future_field"] == "future_value" + + def test_metadata_with_no_extra_fields(self): + """Test that metadata works normally when no extra fields are provided.""" + data = { + "dbt_version": "1.9.0", + "generated_at": "2025-11-05T10:00:00Z", + } + + metadata = Metadata(**data) + + assert metadata.dbt_version == "1.9.0" + assert metadata.generated_at == "2025-11-05T10:00:00Z" + + def test_metadata_with_only_extra_fields(self): + """Test that metadata accepts data with only extra fields (all known fields are Optional).""" + data = { + "some_new_field": "value", + "another_new_field": 42, + } + + # This should work since all defined fields are Optional + metadata = Metadata(**data) + + assert metadata.__pydantic_extra__["some_new_field"] == "value" + assert metadata.__pydantic_extra__["another_new_field"] == 42 + + def test_invocation_started_at_as_extra_field(self): + """Test the specific case of invocation_started_at being handled as an extra field.""" + # This is the real-world scenario: dbt adds invocation_started_at + data = { + "dbt_schema_version": "https://schemas.getdbt.com/dbt/catalog/v1.json", + "dbt_version": "1.9.0", + "generated_at": "2025-11-05T10:00:00Z", + "invocation_id": "abc-123-def-456", + "invocation_started_at": "2025-11-05T09:55:30.123456Z", + } + + # Should not raise ValidationError + metadata = Metadata(**data) + + # The field should be accessible via __pydantic_extra__ + assert metadata.__pydantic_extra__["invocation_started_at"] == "2025-11-05T09:55:30.123456Z" + + # And should be included in model_dump() + dumped = metadata.model_dump() + assert dumped["invocation_started_at"] == "2025-11-05T09:55:30.123456Z" From 62191409a7dfea8d7269b501742ce8abc0843b4c Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 15:40:03 -0800 Subject: [PATCH 2/9] fix: rename tests/vendor to tests/test_vendor to avoid import conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tests/vendor/ directory was conflicting with src/vendor/ in pytest's import resolution. When pytest added tests/ to sys.path, it would import tests/vendor/__init__.py instead of src/vendor/__init__.py, causing all vendor imports to fail. Renaming to tests/test_vendor/ fixes this conflict and allows tests to run. Also updated test infrastructure: - Enhanced tests/conftest.py with pytest_configure hook - Added README_TESTS.md with instructions for running tests locally - Removed redundant tests/vendor/conftest.py All 6 catalog extra fields tests now pass successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- README_TESTS.md | 62 +++++++++++++++++++ tests/conftest.py | 11 ++++ tests/{vendor => test_vendor}/__init__.py | 0 .../test_catalog_v1.py | 0 tests/vendor/conftest.py | 7 --- 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 README_TESTS.md rename tests/{vendor => test_vendor}/__init__.py (100%) rename tests/{vendor => test_vendor}/test_catalog_v1.py (100%) delete mode 100644 tests/vendor/conftest.py diff --git a/README_TESTS.md b/README_TESTS.md new file mode 100644 index 00000000..50a2f5ea --- /dev/null +++ b/README_TESTS.md @@ -0,0 +1,62 @@ +# Running Tests + +## Quick Start + +The easiest way to run the catalog extra fields tests: + +```bash +# Activate virtual environment +source .venv/bin/activate + +# Run catalog extra fields tests +python -m pytest tests/test_vendor/test_catalog_v1.py -v +``` + +## All Test Commands + +```bash +# Run all catalog vendor tests +python -m pytest tests/test_vendor/ -v + +# Run specific test file +python -m pytest tests/test_vendor/test_catalog_v1.py -v + +# Run specific test class +python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields -v + +# Run specific test method +python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields::test_metadata_accepts_extra_fields -v + +# Run with more verbose output +python -m pytest tests/test_vendor/test_catalog_v1.py -vv + +# Run and show print statements +python -m pytest tests/test_vendor/test_catalog_v1.py -v -s + +# Run all tests in the project +python -m pytest tests/ -v +``` + +## Using tox (Recommended for full test suite) + +The GitHub Actions CI uses tox to run tests across multiple Python and Pydantic versions: + +```bash +# Run tests with Python 3.10 and Pydantic 2.10 (no coverage) +python3 -m tox -e py310-pydantic210-nocov + +# Run tests with coverage +python3 -m tox -e py310-pydantic210-cover + +# Run specific tests with tox +python3 -m tox -e py310-pydantic210-nocov -- tests/test_vendor/test_catalog_v1.py +``` + +## Continuous Integration + +Tests run automatically on every push and pull request via GitHub Actions (`.github/workflows/github-actions.yml`). + +The CI runs tests across: +- Python versions: 3.10, 3.11, 3.12, PyPy 3.10 +- Pydantic versions: 2.8, 2.10 +- With and without coverage reports diff --git a/tests/conftest.py b/tests/conftest.py index bf0fd0c0..50792042 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,17 @@ from pathlib import Path # Add src directory to Python path for all tests +# This needs to run at import time, before pytest collects tests src_path = Path(__file__).parent.parent / "src" if str(src_path) not in sys.path: sys.path.insert(0, str(src_path)) + + +def pytest_configure(config): + """ + Hook that runs before test collection. + Ensures src directory is in path before pytest imports test modules. + """ + # Double-check src is in path + if str(src_path) not in sys.path: + sys.path.insert(0, str(src_path)) diff --git a/tests/vendor/__init__.py b/tests/test_vendor/__init__.py similarity index 100% rename from tests/vendor/__init__.py rename to tests/test_vendor/__init__.py diff --git a/tests/vendor/test_catalog_v1.py b/tests/test_vendor/test_catalog_v1.py similarity index 100% rename from tests/vendor/test_catalog_v1.py rename to tests/test_vendor/test_catalog_v1.py diff --git a/tests/vendor/conftest.py b/tests/vendor/conftest.py deleted file mode 100644 index 42d2df08..00000000 --- a/tests/vendor/conftest.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Pytest configuration for vendor tests.""" -import sys -from pathlib import Path - -# Add src directory to Python path -src_path = Path(__file__).parent.parent.parent / "src" -sys.path.insert(0, str(src_path)) From 7a9790ab8bf1027e5ae54b0d6bf6a2c6d4105126 Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 15:44:46 -0800 Subject: [PATCH 3/9] feat: add Makefile with common development targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add convenient make targets for development workflow: - make help: Display all available commands - make venv: Create virtual environment - make install: Install package and dev dependencies - make test: Run tests quickly - make test-vendor: Run catalog vendor tests - make test-cov: Run tests with coverage - make test-all: Run full tox test suite - make lint: Run code quality checks - make format: Format code - make clean: Clean build artifacts Follows the same help format as toolbox-altimate/Makefile. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Makefile | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..e1143724 --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +.PHONY: help venv install test test-vendor test-cov test-all clean lint format + +## help - Display help about make targets for this Makefile +help: + @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t + +## venv - Create virtual environment +venv: + python3 -m venv .venv + .venv/bin/pip install --upgrade pip + @echo "" + @echo "Virtual environment created. Activate with:" + @echo " source .venv/bin/activate" + +## install - Install package and dependencies in development mode +install: + pip install -e . + pip install pytest pytest-cov tox pre-commit ruff + +## test - Run tests quickly +test: + python -m pytest tests/ -v + +## test-vendor - Run catalog vendor tests +test-vendor: + python -m pytest tests/test_vendor/test_catalog_v1.py -v + +## test-cov - Run tests with coverage report +test-cov: + python -m pytest --cov=src --cov-report=term-missing --cov-report=html tests/ -v + +## test-all - Run full test suite with tox (all Python/Pydantic versions) +test-all: + tox + +## lint - Run code quality checks +lint: + pre-commit run --all-files + +## format - Format code with ruff +format: + ruff format src/ tests/ + +## clean - Remove build artifacts and cache +clean: + rm -rf build/ + rm -rf dist/ + rm -rf *.egg-info + rm -rf .pytest_cache/ + rm -rf .tox/ + rm -rf htmlcov/ + rm -rf .coverage + find . -type d -name __pycache__ -exec rm -rf {} + + find . -type f -name '*.pyc' -delete From 8065f05fec9812fb9f69b22e676ec4e0016ead09 Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 15:44:59 -0800 Subject: [PATCH 4/9] docs: update README_TESTS.md to highlight Makefile usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update test documentation to recommend make commands as the primary method for running tests, with manual pytest commands as a fallback. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- README_TESTS.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README_TESTS.md b/README_TESTS.md index 50a2f5ea..204398c0 100644 --- a/README_TESTS.md +++ b/README_TESTS.md @@ -1,8 +1,30 @@ # Running Tests -## Quick Start +## Quick Start (Using Make) -The easiest way to run the catalog extra fields tests: +The easiest way to run tests: + +```bash +# First time setup - create virtual environment +make venv +source .venv/bin/activate + +# Install dependencies +make install + +# Run all tests +make test + +# Run just the catalog vendor tests +make test-vendor + +# Run tests with coverage +make test-cov +``` + +## Manual Test Commands + +If you prefer to run pytest directly: ```bash # Activate virtual environment From 5e538c456a0cd526edfea2f654a74274f8f34a7f Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 17:59:39 -0800 Subject: [PATCH 5/9] Remove redundant README_TESTS.md The main README.md already documents test running in the Development section, and the Makefile provides 'make help' with all test commands. This eliminates maintenance burden of keeping multiple documentation files in sync. --- README_TESTS.md | 84 ------------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 README_TESTS.md diff --git a/README_TESTS.md b/README_TESTS.md deleted file mode 100644 index 204398c0..00000000 --- a/README_TESTS.md +++ /dev/null @@ -1,84 +0,0 @@ -# Running Tests - -## Quick Start (Using Make) - -The easiest way to run tests: - -```bash -# First time setup - create virtual environment -make venv -source .venv/bin/activate - -# Install dependencies -make install - -# Run all tests -make test - -# Run just the catalog vendor tests -make test-vendor - -# Run tests with coverage -make test-cov -``` - -## Manual Test Commands - -If you prefer to run pytest directly: - -```bash -# Activate virtual environment -source .venv/bin/activate - -# Run catalog extra fields tests -python -m pytest tests/test_vendor/test_catalog_v1.py -v -``` - -## All Test Commands - -```bash -# Run all catalog vendor tests -python -m pytest tests/test_vendor/ -v - -# Run specific test file -python -m pytest tests/test_vendor/test_catalog_v1.py -v - -# Run specific test class -python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields -v - -# Run specific test method -python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields::test_metadata_accepts_extra_fields -v - -# Run with more verbose output -python -m pytest tests/test_vendor/test_catalog_v1.py -vv - -# Run and show print statements -python -m pytest tests/test_vendor/test_catalog_v1.py -v -s - -# Run all tests in the project -python -m pytest tests/ -v -``` - -## Using tox (Recommended for full test suite) - -The GitHub Actions CI uses tox to run tests across multiple Python and Pydantic versions: - -```bash -# Run tests with Python 3.10 and Pydantic 2.10 (no coverage) -python3 -m tox -e py310-pydantic210-nocov - -# Run tests with coverage -python3 -m tox -e py310-pydantic210-cover - -# Run specific tests with tox -python3 -m tox -e py310-pydantic210-nocov -- tests/test_vendor/test_catalog_v1.py -``` - -## Continuous Integration - -Tests run automatically on every push and pull request via GitHub Actions (`.github/workflows/github-actions.yml`). - -The CI runs tests across: -- Python versions: 3.10, 3.11, 3.12, PyPy 3.10 -- Pydantic versions: 2.8, 2.10 -- With and without coverage reports From e1de9eec8fe8e788cb04f9bb11c979801f6c2dcb Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 18:06:18 -0800 Subject: [PATCH 6/9] Revert "Remove redundant README_TESTS.md" This reverts commit 5e538c456a0cd526edfea2f654a74274f8f34a7f. --- README_TESTS.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 README_TESTS.md diff --git a/README_TESTS.md b/README_TESTS.md new file mode 100644 index 00000000..204398c0 --- /dev/null +++ b/README_TESTS.md @@ -0,0 +1,84 @@ +# Running Tests + +## Quick Start (Using Make) + +The easiest way to run tests: + +```bash +# First time setup - create virtual environment +make venv +source .venv/bin/activate + +# Install dependencies +make install + +# Run all tests +make test + +# Run just the catalog vendor tests +make test-vendor + +# Run tests with coverage +make test-cov +``` + +## Manual Test Commands + +If you prefer to run pytest directly: + +```bash +# Activate virtual environment +source .venv/bin/activate + +# Run catalog extra fields tests +python -m pytest tests/test_vendor/test_catalog_v1.py -v +``` + +## All Test Commands + +```bash +# Run all catalog vendor tests +python -m pytest tests/test_vendor/ -v + +# Run specific test file +python -m pytest tests/test_vendor/test_catalog_v1.py -v + +# Run specific test class +python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields -v + +# Run specific test method +python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields::test_metadata_accepts_extra_fields -v + +# Run with more verbose output +python -m pytest tests/test_vendor/test_catalog_v1.py -vv + +# Run and show print statements +python -m pytest tests/test_vendor/test_catalog_v1.py -v -s + +# Run all tests in the project +python -m pytest tests/ -v +``` + +## Using tox (Recommended for full test suite) + +The GitHub Actions CI uses tox to run tests across multiple Python and Pydantic versions: + +```bash +# Run tests with Python 3.10 and Pydantic 2.10 (no coverage) +python3 -m tox -e py310-pydantic210-nocov + +# Run tests with coverage +python3 -m tox -e py310-pydantic210-cover + +# Run specific tests with tox +python3 -m tox -e py310-pydantic210-nocov -- tests/test_vendor/test_catalog_v1.py +``` + +## Continuous Integration + +Tests run automatically on every push and pull request via GitHub Actions (`.github/workflows/github-actions.yml`). + +The CI runs tests across: +- Python versions: 3.10, 3.11, 3.12, PyPy 3.10 +- Pydantic versions: 2.8, 2.10 +- With and without coverage reports From 9d87ab977e4ba2be4a7a6473956446b10ae675bc Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 18:07:51 -0800 Subject: [PATCH 7/9] docs: migrate test documentation from README_TESTS.md to CONTRIBUTING.rst Move all test running instructions to CONTRIBUTING.rst under a new 'Running Tests' section with subsections for: - Quick Start (Using Make) - Manual Test Commands - All Test Commands - Using tox - Continuous Integration This consolidates test documentation in the standard CONTRIBUTING.rst location where developers expect to find contribution guidelines. Remove README_TESTS.md after content migration to avoid duplication. Keep tests/conftest.py as it's required for nocov test mode where the package is not installed in editable mode (usedevelop=false in tox.ini). --- CONTRIBUTING.rst | 87 ++++++++++++++++++++++++++++++++++++++++++++++-- README_TESTS.md | 84 ---------------------------------------------- 2 files changed, 85 insertions(+), 86 deletions(-) delete mode 100644 README_TESTS.md diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index a45f6cff..d04c98a4 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -73,8 +73,80 @@ For merging, you should: 3. Add a note to ``CHANGELOG.rst`` about the changes. 4. Add yourself to ``AUTHORS.rst``. -Tips ----- +Running Tests +------------- + +Quick Start (Using Make) +~~~~~~~~~~~~~~~~~~~~~~~~ + +The easiest way to run tests:: + + # First time setup - create virtual environment + make venv + source .venv/bin/activate + + # Install dependencies + make install + + # Run all tests + make test + + # Run just the catalog vendor tests + make test-vendor + + # Run tests with coverage + make test-cov + +Manual Test Commands +~~~~~~~~~~~~~~~~~~~~ + +If you prefer to run pytest directly:: + + # Activate virtual environment + source .venv/bin/activate + + # Run catalog extra fields tests + python -m pytest tests/test_vendor/test_catalog_v1.py -v + +All Test Commands +~~~~~~~~~~~~~~~~~ + +:: + + # Run all catalog vendor tests + python -m pytest tests/test_vendor/ -v + + # Run specific test file + python -m pytest tests/test_vendor/test_catalog_v1.py -v + + # Run specific test class + python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields -v + + # Run specific test method + python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields::test_metadata_accepts_extra_fields -v + + # Run with more verbose output + python -m pytest tests/test_vendor/test_catalog_v1.py -vv + + # Run and show print statements + python -m pytest tests/test_vendor/test_catalog_v1.py -v -s + + # Run all tests in the project + python -m pytest tests/ -v + +Using tox +~~~~~~~~~ + +The GitHub Actions CI uses tox to run tests across multiple Python and Pydantic versions:: + + # Run tests with Python 3.10 and Pydantic 2.10 (no coverage) + python3 -m tox -e py310-pydantic210-nocov + + # Run tests with coverage + python3 -m tox -e py310-pydantic210-cover + + # Run specific tests with tox + python3 -m tox -e py310-pydantic210-nocov -- tests/test_vendor/test_catalog_v1.py To run a subset of tests:: @@ -83,3 +155,14 @@ To run a subset of tests:: To run all the test environments in *parallel*:: tox -p auto + +Continuous Integration +~~~~~~~~~~~~~~~~~~~~~~ + +Tests run automatically on every push and pull request via GitHub Actions (``.github/workflows/github-actions.yml``). + +The CI runs tests across: + +* Python versions: 3.10, 3.11, 3.12, PyPy 3.9 +* Pydantic versions: 2.8, 2.10 +* With and without coverage reports diff --git a/README_TESTS.md b/README_TESTS.md deleted file mode 100644 index 204398c0..00000000 --- a/README_TESTS.md +++ /dev/null @@ -1,84 +0,0 @@ -# Running Tests - -## Quick Start (Using Make) - -The easiest way to run tests: - -```bash -# First time setup - create virtual environment -make venv -source .venv/bin/activate - -# Install dependencies -make install - -# Run all tests -make test - -# Run just the catalog vendor tests -make test-vendor - -# Run tests with coverage -make test-cov -``` - -## Manual Test Commands - -If you prefer to run pytest directly: - -```bash -# Activate virtual environment -source .venv/bin/activate - -# Run catalog extra fields tests -python -m pytest tests/test_vendor/test_catalog_v1.py -v -``` - -## All Test Commands - -```bash -# Run all catalog vendor tests -python -m pytest tests/test_vendor/ -v - -# Run specific test file -python -m pytest tests/test_vendor/test_catalog_v1.py -v - -# Run specific test class -python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields -v - -# Run specific test method -python -m pytest tests/test_vendor/test_catalog_v1.py::TestMetadataExtraFields::test_metadata_accepts_extra_fields -v - -# Run with more verbose output -python -m pytest tests/test_vendor/test_catalog_v1.py -vv - -# Run and show print statements -python -m pytest tests/test_vendor/test_catalog_v1.py -v -s - -# Run all tests in the project -python -m pytest tests/ -v -``` - -## Using tox (Recommended for full test suite) - -The GitHub Actions CI uses tox to run tests across multiple Python and Pydantic versions: - -```bash -# Run tests with Python 3.10 and Pydantic 2.10 (no coverage) -python3 -m tox -e py310-pydantic210-nocov - -# Run tests with coverage -python3 -m tox -e py310-pydantic210-cover - -# Run specific tests with tox -python3 -m tox -e py310-pydantic210-nocov -- tests/test_vendor/test_catalog_v1.py -``` - -## Continuous Integration - -Tests run automatically on every push and pull request via GitHub Actions (`.github/workflows/github-actions.yml`). - -The CI runs tests across: -- Python versions: 3.10, 3.11, 3.12, PyPy 3.10 -- Pydantic versions: 2.8, 2.10 -- With and without coverage reports From 27240b445b4135c4f07a94e542a4a46116f4fc9e Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Thu, 6 Nov 2025 18:09:37 -0800 Subject: [PATCH 8/9] docs: enhance conftest.py comments to explain why it's required Add detailed docstring explaining that conftest.py is needed for tox nocov mode where usedevelop=false and the package isn't installed. This clarifies the purpose for future maintainers who might wonder if this file can be removed. --- tests/conftest.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 50792042..5a660083 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,21 @@ -"""Root pytest configuration.""" +"""Root pytest configuration. + +This file is required for tests to work in tox nocov mode (usedevelop=false). + +In tox.ini, the usedevelop setting varies: +- cover mode: usedevelop=true (package installed in editable mode) +- nocov mode: usedevelop=false (package NOT installed) + +When usedevelop=false, Python can't find the vendor module for imports like: + from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import Metadata + +This conftest.py adds src/ to sys.path so imports work in both modes. +""" import sys from pathlib import Path # Add src directory to Python path for all tests -# This needs to run at import time, before pytest collects tests +# This runs at import time, before pytest collects test modules src_path = Path(__file__).parent.parent / "src" if str(src_path) not in sys.path: sys.path.insert(0, str(src_path)) @@ -12,7 +24,9 @@ def pytest_configure(config): """ Hook that runs before test collection. - Ensures src directory is in path before pytest imports test modules. + + Ensures src directory is in sys.path before pytest imports test modules. + This is a safety check in case the module-level code above didn't run. """ # Double-check src is in path if str(src_path) not in sys.path: From 9a5979fdfe4ce52433750ca9944b0643b6bed5e3 Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Fri, 7 Nov 2025 09:55:42 -0800 Subject: [PATCH 9/9] Remove unnecessary tests/conftest.py After further investigation, conftest.py is not needed because: 1. When tox installs the package (even with usedevelop=false), it runs 'pip install .' which installs ALL packages found by find_packages('src') including both 'datapilot' and 'vendor' packages. 2. The existing tests (tests/core/**) import from 'datapilot' and work fine without any conftest.py manipulating sys.path. 3. The actual fix for our import issues was renaming tests/vendor/ to tests/test_vendor/ to avoid the directory naming conflict with src/vendor/, not adding conftest.py. When the package is properly installed, both 'datapilot' and 'vendor' are importable without needing to manually add src/ to sys.path. --- tests/conftest.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 5a660083..00000000 --- a/tests/conftest.py +++ /dev/null @@ -1,33 +0,0 @@ -"""Root pytest configuration. - -This file is required for tests to work in tox nocov mode (usedevelop=false). - -In tox.ini, the usedevelop setting varies: -- cover mode: usedevelop=true (package installed in editable mode) -- nocov mode: usedevelop=false (package NOT installed) - -When usedevelop=false, Python can't find the vendor module for imports like: - from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import Metadata - -This conftest.py adds src/ to sys.path so imports work in both modes. -""" -import sys -from pathlib import Path - -# Add src directory to Python path for all tests -# This runs at import time, before pytest collects test modules -src_path = Path(__file__).parent.parent / "src" -if str(src_path) not in sys.path: - sys.path.insert(0, str(src_path)) - - -def pytest_configure(config): - """ - Hook that runs before test collection. - - Ensures src directory is in sys.path before pytest imports test modules. - This is a safety check in case the module-level code above didn't run. - """ - # Double-check src is in path - if str(src_path) not in sys.path: - sys.path.insert(0, str(src_path))