pytest-dev / pytest-dev/pytest-django

pytest cannot find database and tables

Open
#942 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Moved from https://github.com/pytest-dev/pytest-xdist/issues/690

OP post:

I am trying to speed up the test runtime by using pytest-xdist, previously I was using pytest, pytest-django to run the tests,

After installing pytest-xdist, One is an issue which I am facing is most of the tests are failing with messages that relation does not exist

pytest -n auto accounts/tests

for example
psycopg2.errors.UndefinedTable: relation "auth_user" does not exist

I guess there is error which says database does not exist:
django.db.utils.OperationalError: FATAL: database "test_dev" does not exist

But the interesting thing is some of tests are passing :(

I am having the same issue even with requesting the fixture django_db_modify_db_settings_parallel_suffix.

pytest -n auto runs 11 cores in my server, and I noticed that this problem happens less with -n 6 cores. And almost never happens with -n 2 . The issue started when we moved to a different server. The original one runs on only 2 cores with
pytest -n auto.

E django.db.utils.OperationalError: FATAL: database "test_dev_gw1" does not exist

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

Start by reproducing pytest -n auto accounts/tests with pytest-xdist and compare it with lower worker counts. Inspect how pytest-django handles django_db_modify_db_settings_parallel_suffix; done means parallel workers reliably find their databases and tables without UndefinedTable or missing-database errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, postgresql, python
Domain
databases, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.