Mock PostgreSQL dependencies in unit tests to enable database-free test runs #281
Labels
No labels
Closed As
complete
Closed As
insufficient data
Closed As
moved
Closed As
out of scope
difficulty
easy
difficulty
hard
difficulty
medium
needs testing
type - backend
type - docs
type - fedora-messaging
type - Flock
type - frontend
type - infra
type - internal organization
type - quality assurance
type - summer coding
type - upstream
function
analytics
function
communications
function
docs
function
events
function
onboarding
function
operations
good first issue
help wanted
needs
changes
needs
reporter feedback
needs
team vote
needs
triage
scope
bug
scope
improvement
scope
new
state
approved
state
blocked
state
duplicate
state
invalid
state
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
commops/fedora-happiness-packets#281
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently 38 of 68 unit tests fail when run outside the Podman Compose environment because they attempt to connect to a PostgreSQL instance at hostname
db. This means the test suite cannot pass in CI without spinning up a PostgreSQL service container, and local development requires a running database for any test feedback.The goal is to mock the database layer so that all unit tests pass without a live PostgreSQL connection. This would:
dbservice dependency from the test job)poetry run pytestworks anywhere)The test settings file (
happinesspackets/settings/tsting.py) currently inherits the PostgreSQL database configuration fromdev.py. Tests that hit the database include model creation viafactory-boyfactories (MessageModelFactory,BlacklistedEmailFactory), view tests that query the ORM, and form validation tests.Possible approaches:
unittest.mockto mock ORM queries in view/form testspytest-django'sdjango_dbmarker with an in-memory SQLite database configured intsting.pyRelated: the CI workflow (
.forgejo/workflows/ci.yml) currently provisions apostgres:15service container for the test job that could be removed once this is resolved.