Skip to content

Conversation

@fizyk
Copy link
Member

@fizyk fizyk commented Jan 20, 2026

This allows for more complex test suites with common base data fixture
Extended for a specific group of tests that needs additional data elements in database

Chore that needs to be done:

  • Add newsfragment pipenv run towncrier create [issue_number].[type].rst

Types are defined in the pyproject.toml, issue_number either from issue tracker or the Pull request number

Summary by CodeRabbit

  • New Features

    • Added a depends_on parameter to enable hierarchical fixture chaining for layered database pre-population.
  • Documentation

    • Added "Chaining fixtures" guidance, examples and an architecture diagram illustrating multi‑layer fixture cloning.
  • Tests

    • Added tests covering two‑ and three‑layer chaining, data propagation and inheritance of connection parameters.
  • Breaking Changes

    • Database janitor/template handling updated to explicit template management with an as_template flag.
  • Chores

    • Minimum pytest requirement bumped to 8.2.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

Walkthrough

Adds fixture chaining for postgresql_noproc via a new depends_on parameter, refactors DatabaseJanitor to require explicit dbname and an as_template flag, updates process integration and tests, adds docs (Mermaid diagram) and release fragments, and bumps the pytest minimum to >= 8.2.

Changes

Cohort / File(s) Summary
Core fixture chaining implementation
pytest_postgresql/factories/noprocess.py
Adds depends_on parameter to postgresql_noproc, resolve connection params from the dependent fixture when set, derive base template DB name, adjust NoopExecutor db naming and fixture signature, and update docstrings.
Database janitor refactor
pytest_postgresql/janitor.py
Makes dbname required, adds as_template: bool, centralises create/load/drop to use self.dbname, and changes template marking/unmarking logic.
Process fixture integration
pytest_postgresql/factories/process.py
Updates DatabaseJanitor construction to dbname=... with as_template=True for template janitors (replacing prior template_dbname=...).
Tests: chaining & adjustments
tests/test_chaining.py, tests/test_postgres_options_plugin.py, tests/test_postgresql.py
Adds tests/test_chaining.py for multi-layer fixture tests; updates tests to the new DatabaseJanitor signature/attributes; replaces a version-based skip with an xdist group.
Documentation
README.rst, docs/architecture_chaining.mmd
Adds "Chaining fixtures" section and example to README and a Mermaid diagram file illustrating layered fixture orchestration.
Release notes
newsfragments/890.break.rst, newsfragments/890.docs.rst, newsfragments/890.feature.rst, newsfragments/890.break.1.rst
Adds fragments documenting the janitor breaking change, the new depends_on feature, the Mermaid diagram, and the pytest minimum bump.
Packaging / CI
pyproject.toml, oldest/requirements.txt
Bumps pytest minimum to >= 8.2 and pins pytest in oldest requirements (pytest == 8.2).

Sequence Diagram

sequenceDiagram
    participant Test
    participant ProcF as BaseProc (proc fixture)
    participant Noop1 as SeededNoop (noproc fixture)
    participant Noop2 as MoreSeededNoop (noproc fixture)
    participant DB as PostgreSQL Database

    Test->>ProcF: request `base_proc`
    ProcF->>DB: create base_db, load schema
    ProcF-->>Test: return PostgreSQLExecutor (template dbname)

    Test->>Noop1: request `seeded_noproc` (depends_on=`base_proc`)
    Noop1->>ProcF: read connection & template info
    Noop1->>DB: create seeded_db USING TEMPLATE base_db, load data
    Noop1-->>Test: return NoopExecutor (seeded_db)

    Test->>Noop2: request `more_seeded_noproc` (depends_on=`seeded_noproc`)
    Noop2->>Noop1: read connection & template info
    Noop2->>DB: create more_seeded_db USING TEMPLATE seeded_db, load more data
    Noop2-->>Test: return NoopExecutor (more_seeded_db)

    Test->>DB: validate tables and data across layers
    Test-->>Test: assertions
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 I layered databases, one by one,

A base, then seeds beneath the sun,
The janitor marks doors open wide,
Fixtures hop and clone with pride—
Hooray for chaining; carrots: well done!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature addition: enabling chaining of noprocess fixtures, and references the closed issue number for context.
Docstring Coverage ✅ Passed Docstring coverage is 95.24% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fizyk
Copy link
Member Author

fizyk commented Jan 20, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@fizyk fizyk marked this pull request as ready for review January 20, 2026 21:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@pytest_postgresql/factories/noprocess.py`:
- Line 79: The pg_options local is being overwritten unconditionally after the
depends_on/else branches; remove the duplicate assignment so that pg_options
retains the value set in the depends_on branch (base.options) or the else branch
instead of always becoming config.options. Locate the code that assigns
pg_options in the factory function (the assignments at the depends_on branch
that set base.options, the else branch, and the later line `pg_options = options
or config.options`) and delete the later unconditional `pg_options = options or
config.options` so pg_options is only set by the intended branch logic.
🧹 Nitpick comments (1)
tests/test_chaining.py (1)

96-101: Consider adding assertion for options inheritance.

This test validates that host, port, user, and password are inherited, but does not verify options. Given the pg_options overwrite bug identified in noprocess.py, adding an assertion for options would help catch such regressions.

♻️ Suggested addition
     assert seeded_noproc.host == base_proc.host
     assert seeded_noproc.port == base_proc.port
     assert seeded_noproc.user == base_proc.user
     assert seeded_noproc.password == base_proc.password
+    assert seeded_noproc.options == base_proc.options

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/oldest-postgres.yml:
- Line 68: The pytest invocation in the workflow's `command:` duplicates
verbosity flags already present in `pyproject.oldest.toml`; remove `-vv
--setup-show` from the `command:` string so the command becomes `pytest -n auto
-c pyproject.oldest.toml --dist loadgroup --max-worker-restart 0
--postgresql-exec="/usr/lib/postgresql/${{ inputs.postgresql }}/bin/pg_ctl" -k
"not docker" --cov-report=xml:coverage-xdist.xml`, leaving `addopts` in
`pyproject.oldest.toml` to control verbosity.

@fizyk fizyk force-pushed the issue-890 branch 3 times, most recently from 238899e to 34c0d4f Compare January 22, 2026 22:06
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@newsfragments/890.break.1.rst`:
- Around line 3-5: Fix the grammatical issues in the news fragment: change the
phrase "version behave flaky" to "versions behave flakily" (plural subject +
adverb) and remove the redundant word so "fixture chaining fixture" becomes
"fixture chaining". Ensure the resulting sentence reads smoothly with "versions
behave flakily with getfixturefunction requests on Python 3.12-3.13 in fixture
chaining when used alongside xdist."

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@pyproject.toml`:
- Line 31: Add a breaking change newsfragment documenting the pytest bump
introduced in pyproject.toml: create a file in newsfragments/ (e.g.,
1XXXXX.break) that states pytest 8.2+ is now required, including why (what
changed) and migration notes for users; while adding the fragment, also verify
whether pytest 8.2 is truly necessary (inspect the change that prompted the bump
and any usage of features like fixture chaining from pytest-postgresql) and if a
lower pytest version suffices, update pyproject.toml accordingly and adjust the
newsfragment to reflect the accurate minimal required version.

  This allows for more complex test suites with common base data fixture
  Extended for a specific group of tests that needs additional data elements in database

  Also bumped minimal supported pytest version to 8.2 as it's the earliest that safely
  runs fixture chaining
@fizyk fizyk merged commit f478f8f into main Jan 23, 2026
52 checks passed
@fizyk fizyk deleted the issue-890 branch January 23, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants