pytest-dev / pytest-dev/pytest-django

New feature `--lazy-db`: `--reuse-db` with `--create-db` on DB error / ProgrammingError

Open
#212 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
1.5k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

What do you think about a new option --lazy-db, which would behave like --reuse-db, but falls back to --create-db when there's a DB error during the first test.

Would that be possible / feasible?
Could this be done by default, without a new option?

For example:

    def execute(self, sql, params=None):
        self.db.validate_no_broken_transaction()
        self.db.set_dirty()
        with self.db.wrap_database_errors:
            if params is None:
                return self.cursor.execute(sql)
            else:
>               return self.cursor.execute(sql, params)
E               ProgrammingError: relation "languages_plus_language" does not exist
E               LINE 1: ...."family", "languages_plus_language"."notes" FROM "languages...
E                                                                            ^

…/django-1.7.x/django/db/backends/utils.py:65: ProgrammingError

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name files or tests. Start by locating the existing --reuse-db and --create-db handling in pytest-django's database setup, then clarify whether the fallback should be opt-in or default. Done would require an agreed behavior and tests covering recovery from the first database error.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
database, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.