Repository navigation
feat: add rowx.testing pytest plugin - #164
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e87aa5231
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #149
What
src/rowx/testing.py, an opt-in pytest plugin (pytest_plugins = ["rowx.testing"]or-p rowx.testing). Thereis no
pytest11entry point, andimport rowx/import rowx.postgresnever import pytest.rowx_database_urlini option, else thedatabase_url_envvariable from[tool.rowx]. The migrationscome from
[tool.rowx.migrate]through thecheck/config.pyloader andload_migrator. It also registers--rowx-keep-templates.rowx_tpl_<hash>(sha256, first 16 hex chars) over everything that shapes the template: the historytable, thecreate_schemas(sorted, deduplicated) and the sorted forward(version, checksum)list. A config changetherefore builds a new template instead of reusing one built under the old config.
postgresmaintenance database, the one the adminhelpers use for these names, so sessions whose URLs select different databases still serialise on it (advisory locks
are per database). The check, build and stale cleanup, and every clone, run under it.
COMMENT ON DATABASEmark; an existing unmarked one (a build thatdied) is dropped and rebuilt. The build connection is closed before the mark is written and before any clone.
maintenance database) for the whole session, taken before the build lock is released. Stale cleanup only drops a
rowx_tpl_*database when it can take that key exclusively, so a template another live session is using (idlebetween clones) is never dropped. Cleanup runs after a new build unless
--rowx-keep-templatesis set.asyncio.run):rowx_database_urlclones the template asrowx_test_<hex>(URL built withwith_database) and drops itWITH (FORCE)at teardown, also after a failing test;rowx_connectionandrowx_poolsit on top of it.ROWX_REQUIRE_DB=1they fail. Failures while building, cloning or droppingare reported with the URL redacted.
New tests
All in
src/rowx/__tests__/integration/test_testing.py. Inner sessions run as pytest subprocesses.test_importing_rowx_does_not_import_pytest(subprocess; not DB)test_template_name_follows_the_migrations_and_their_config(not DB; coverstableandcreate_schemas)test_plugin_is_inactive_unless_opted_intest_no_url_skips_or_fails[False|True]test_url_comes_from_the_database_url_env(db)test_each_test_gets_an_isolated_migrated_database(db)test_a_failing_test_still_drops_its_clone(db)test_pool_and_connection_work_in_a_coroutine(db)test_template_is_reused_then_rebuilt_when_a_migration_changes(db; also asserts stale cleanup)test_a_config_change_rebuilds_the_template(db)test_keep_templates_keeps_the_stale_template(db)test_an_incomplete_template_is_rebuilt(db)test_a_failing_migration_reports_and_leaves_nothing(db)test_cleanup_spares_a_template_another_session_holds(db): one session sits idle between clones (gated on anadvisory lock, synchronised with
LISTEN/NOTIFY) while a second session, with other migrations and a URL selectinganother database, builds its template and runs cleanup; the first session's next clone still succeeds.
test_sessions_on_different_databases_share_the_build_lock(db): two sessions with the same migrations and URLsselecting different databases both queue on the one build lock (polled in
pg_locks, neversleep), then both passon the one template. This stands in for the xdist case.
test_the_template_is_built_once_under_xdist(db; skips because xdist is not in the dev group)The
projectfixture asserts that no newrowx_test_*database outlives each test and drops the templates it created.pytest-asyncio and anyio are not dev dependencies, so the issue's "from a pytest-asyncio test" case is covered by a plain
sync test that drives the fixtures through
asyncio.run. No dependencies were added to the dev group.Wiring and out-of-scope edits
pyproject.toml: new optional extrapytest = ["pytest>=9.1.1"](and the matchinguv.lockchange).ty'smissing-direct-dependencyrule rejectsimport pytestinsrc/rowx/testing.pyunless pytest is a declareddependency. The extra declares what the plugin really needs (
rowx[pytest]) without making pytest a runtimedependency, and avoids both a suppression and a linter-config change. Note that
architecture.mdsays pytest "stays inthe dev group"; it still does, and the extra is an addition the design may want to mention.
crates/rowx-postgres/tests/migrate.rs'sTestDbleaked itsrowx_mig_*database whenever a testfailed (a panicking assert or an early
?skippedfinish). It now drops the database inDrop(on a fresh runtimein its own thread) unless
finishalready did.unit/test_testing.pywould clash with it on the modulebasename (neither directory is a package).
Spec ambiguities
COMMENT ON DATABASEmark written after the migrations succeed.(version, checksum). This PR also hashes the historytableandcreate_schemas,since both change what the template holds;
.down.sqlfiles are left out. Proposed design change: "over themigration config and the
(version, checksum)list".postgresmaintenance database, and sessions mark their template in use with a sharedadvisory lock; neither is spelled out by the design.
template0(as--scratchdoes), nottemplate1.session is connected to.
is built.
🤖 Generated with Claude Code