Add basic database model test suite - #12
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an initial PyTest-based integration test suite for the carpi-data-model SQLAlchemy models by running against an ephemeral MySQL 8.0 instance via testcontainers, and wires it into GitHub Actions while updating docs and Python version requirements.
Changes:
- Added
tests/test_models.pyto create/drop all tables per test and validate a basic insert/query path. - Added a GitHub Actions workflow to run the test suite on pushes/PRs.
- Updated documentation, Python minimum version, and project/test dependencies to support Docker + pytest execution.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_models.py |
New MySQL-backed model tests using testcontainers and SQLAlchemy. |
requirements.txt |
Adds pinned test/development dependencies (including a self-referential VCS dependency). |
README.md |
Expands installation and local testing instructions; documents Docker requirement for tests. |
pyproject.toml |
Bumps required Python version to 3.10. |
.github/workflows/test.yml |
Adds CI workflow to run pytest in GitHub Actions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Previously, the test only ensured that the Python model declarations were correct, which didn't imply that the tables were successfully created in the database. Although, I suppose this test wouldn't run in the first place if the setup_database fixture failed beforehand.
jzgom067
previously approved these changes
Apr 8, 2026
Previously, there was a major potential issue during development in which local changes to the package would not be tested properly. This was the old dependency line would fetch the latest commit from the default git branch and PyTest would test that code, effectively making the tests meaningless. This new dependency line basically adds all files in the current working directory to the Python PATH, and this only needs to be done once as Python will automatically track changes to the source code upon each import of the package. The GitHub Action job has also been simplified to reflect this new change.
jzgom067
approved these changes
Apr 9, 2026
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.
What?
This pull request introduces a Docker and PyTest-based test suite for the database models defined in the
carpi-data-modelPython package, as well as a GitHub Action job to automatically run the test suite on commit push.This implicitly adds Docker as a dependency for running the test suites locally, which has been noted in the updated
README.md.There are only a couple of basic tests for now: a test to ensure all tables can be created successfully and that a row can be inserted and queried from the Subject table correctly.
Closes #8.
Why?
The absence of tests has been my greatest pain point with developing models in this package. I have no way of telling whether a model I just wrote contains a syntax error or will cause a SQL error when actually called upon, unless I commit the changes first and test it later in another repository that imports this one.
With the introduction of a basic test suite, I can quickly verify that the models behave properly in a real MySQL environment.
How?
The test suite as a whole uses an ephemeral MySQL 8.0 server instance spun up as a Docker container, which is all done in the
engine()fixture. In this function, the Docker container is spun up using thetestcontainerspackage, and a SQLAlchemy engine is returned and kept alive for the duration of the test session.For each test function in the file, all tables defined in the models file are created and then dropped at the end of the test function.
Credit goes to Gemini Pro 3.1 for getting me started with the basic test file structure.
A
.github/workflows/test.ymlfile has been created to define a GitHub Action job for automatically running the test suite on GitHub servers.README.mdhas also been updated to include instructions for installing this repository as a dependency and contributing to the models and running the test suite locally.Testing?
This is the test. They pass for now.