pytest-dev / pytest-dev/pytest-django
Database setup throwing "--durations" numbers out of whack
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
Running pytest-xdist with concurrency 20, most of my tests access the database. That means that the first 20 tests set up the database for their individual thread, causing the "setup" for the first 20 tests act as if they take ~80s each.
88.01s setup module/test_file.py::test_that_happens_to_run_1
87.04s setup module/test_file.py::test_that_happens_to_run_2
86.41s setup module/test_file.py::test_that_happens_to_run_3
85.46s setup module/test_file.py::test_that_happens_to_run_4
85.44s setup module/test_file.py::test_that_happens_to_run_5
85.31s setup module/test_file.py::test_that_happens_to_run_6
85.30s setup module/test_file.py::test_that_happens_to_run_7
84.99s setup module/test_file.py::test_that_happens_to_run_8
83.58s setup module/test_file.py::test_that_happens_to_run_9
83.54s setup module/test_file.py::test_that_happens_to_run_10
83.49s setup module/test_file.py::test_that_happens_to_run_11
83.16s setup module/test_file.py::test_that_happens_to_run_12
83.03s setup module/test_file.py::test_that_happens_to_run_13
82.95s setup module/test_file.py::test_that_happens_to_run_14
81.64s setup module/test_file.py::test_that_happens_to_run_15
81.57s setup module/test_file.py::test_that_happens_to_run_17
80.93s setup module/test_file.py::test_that_happens_to_run_18
80.73s setup module/test_file.py::test_that_happens_to_run_19
80.73s setup module/test_file.py::test_that_happens_to_run_20
Is there a fixture with autouse and scope=session that can start the database, independent of my tests, so the duration is not counted against my test?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with pytest-xdist at 20 workers and tests that access the database. Start by reading pytest-django's database setup and session-scoped fixture behavior; done means database initialization no longer makes each test's reported setup duration appear to include the shared startup time.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- database, testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100