Skip to content

Add basic database model test suite - #12

Merged
jzgom067 merged 13 commits into
mainfrom
model-tests
Apr 9, 2026
Merged

Add basic database model test suite#12
jzgom067 merged 13 commits into
mainfrom
model-tests

Conversation

@ramonechen

@ramonechen ramonechen commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

What?

This pull request introduces a Docker and PyTest-based test suite for the database models defined in the carpi-data-model Python 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 the testcontainers package, 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.yml file has been created to define a GitHub Action job for automatically running the test suite on GitHub servers.

README.md has 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.

@ramonechen
ramonechen marked this pull request as ready for review April 7, 2026 23:25
@ramonechen
ramonechen requested review from Copilot and jzgom067 April 7, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py to 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.

Comment thread .github/workflows/test.yml Outdated
Comment thread tests/test_models.py Outdated
Comment thread tests/test_models.py Outdated
Comment thread tests/test_models.py Outdated
ramonechen and others added 5 commits April 7, 2026 19:29
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
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
jzgom067 merged commit b59abe9 into main Apr 9, 2026
2 checks passed
@jzgom067
jzgom067 deleted the model-tests branch April 9, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write tests for SQLAlchemy models

3 participants