Repository navigation
Conversation
5043519 to
48e6d90
Compare
MoralCode
left a comment
There was a problem hiding this comment.
@Dev10-sys thanks for the PR! This PR includes a lot of things.
I have also been working on a similar PR to add this kind of testing infrastructure (#583), Could you maybe code review my version? id like sure I'm covering most of the same features in that pr as well
Sorry for forgetting to self-assign the relevant issue to indicate it was being worked on already!
| @pytest.mark.db | ||
| def test_startup_forge_instance_population_use_case(db_engine, schema_factory): | ||
| """Verify database-backed startup data population (CollectOSS issue #577 and PR #575 use case).""" | ||
| schema = schema_factory("startup_test") |
There was a problem hiding this comment.
This is an interesting pattern for specifying a schema name!
There was a problem hiding this comment.
Thanks. The per-test schema isolation prevents tests from stepping on each other's data and avoids table-level truncate locks when running tests concurrently.
|
|
||
|
|
||
| @pytest.mark.db | ||
| def test_startup_forge_instance_population_use_case(db_engine, schema_factory): |
There was a problem hiding this comment.
This tests a feature that hasnt yet been merged
| def pytest_configure(config): | ||
| """Register custom pytest markers.""" | ||
| config.addinivalue_line( | ||
| "markers", | ||
| "db: mark test as requiring a database connection (skipped when no database URL is provided)", | ||
| ) | ||
|
|
There was a problem hiding this comment.
What does this do? this PR already defines the db marker in pyproject.toml
There was a problem hiding this comment.
You're completely right since it's already registered statically in pyproject.toml, the dynamic addinivalue_line in pytest_configure is redundant and can be removed
48e6d90 to
8a3fd64
Compare
Introduce reusable pytest database fixtures supporting schema isolation and automatic skipping when no database is configured. - Add db pytest marker and CLI option --db-url for database test runs - Support TEST_DB_URL, COLLECTOSS_DB, and AUGUR_DB environment variables - Implement db_engine session fixture with connectivity validation - Add blank_db_schema and schema_factory fixtures creating per-test PostgreSQL schemas that automatically drop with CASCADE on teardown - Add db_session and collectoss_db_session fixtures operating within isolated schemas - Add docker-compose.test.yml for running database tests locally - Add unit and integration tests verifying schema isolation and fixture lifecycle Fixes chaoss#577 Signed-off-by: Dev10-sys <kalpanagola9897@gmail.com>
8a3fd64 to
505ab5e
Compare
|
@Dev10-sys what do you think of closing this PR and continuing to collaborate on #583 ? i think we have some good conversations started there already |
|
Many of the ideas from this PR have been incorporated into #583 (with attribution given). Closing as superseded. |
Description
This PR addresses #577 by introducing a unified, reusable set of pytest fixtures for database-backed tests across CollectOSS.
Previously, the test setup relied on root-level PostgreSQL privileges to create and drop entire databases, which fails in non-superuser environments and causes test collisions during parallel runs. I reworked conftest.py to use dynamic per-test schema isolation instead. Each test that needs a clean database environment gets its own isolated PostgreSQL schema ( est_schema_), which automatically drops with CASCADE during teardown. This ensures complete isolation without requiring special database permissions.
Along with the core engine and session fixtures (db_engine, db_session, �lank_db_schema, schema_factory, and collectoss_db_session), I added automatic skip handling. When no database connection string is configured via environment variables (COLLECTOSS_DB, TEST_DB_URL) or CLI flags (--db-url), all database-marked tests gracefully skip with an informative reason rather than erroring out. I also added a minimal docker-compose.test.yml so contributors can easily spin up a local PostgreSQL test container with a single command, as well as a test suite in ests/test_application/test_db/test_db_fixtures.py that validates the fixtures against schema isolation, multi-schema independence, session lifecycles, and materialized view creation and refresh. All 138 existing unit tests continue to pass cleanly.
This PR fixes #577
Notes for Reviewers
All unit tests run and pass without requiring any database running locally. For CI, database tests will skip cleanly until a PostgreSQL service container or connection URL is supplied. The legacy fixtures have also been maintained and routed through the new engine logic to ensure full backwards compatibility with existing test files.
Signed commits
Generative AI disclosure
Please select one option: