pytest-dev / pytest-dev/pytest-django

Support database access for "session" level fixtures.

Open
#243 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Our test suite uses a custom TestRunner which has a run_suite method like so:

def run_suite(self, suite, **kwargs):
    call_command('loaddata', 'foo')
    call_command('loaddata', 'bar')
    return super(CustomTestRunner, self).run_suite(suite, **kwargs)

The fixtures it loads are indeed so common it makes sense just to load them for every test case. For example we host multiple Sites off of our app and one of the fixtures loads a subset of those Site objects. Foreign keys to Site exist in almost all our apps so it makes sense to just load a few before the whole suite.

Although in theory I should be able to rename the fixtures to initial_data.json and have them load, that is for whatever strange reason not working. That is when I found there is no way to duct-tape over it in py.test, because the only time db access is allowed is at the function level.

Are there any plans to include a session-level fixture for db access?

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 tracing the custom TestRunner.run_suite pattern and the function-level db fixture behavior described in the issue; no repository files or tests are named. Done means the test suite supports session-level database access for loading shared Django fixtures.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.