pytest-dev / pytest-dev/pytest-django
Support database access for "session" level fixtures.
Nobody has claimed this yet.
- 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
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
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