pytest-dev / pytest-dev/pytest-django
Apply "django_db" mark to tests using the database
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
I think it's useful to have the "django_db" mark applied for tests using the db fixture (but are not marked explicitly using @pytest.mark.django_db).
The following seems to work, but there might be a better approach to this:
def pytest_collection_modifyitems(items):
for item in items:
if "db" in item.funcargnames:
item.add_marker(pytest.mark.django_db)
This allows to run only tests not using the DB: py.test -m 'not django_db'
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 reviewing the pytest collection hook and the db fixture behavior described in the issue. Implement automatic django_db marking for tests that use db, then verify that selecting -m 'not django_db' excludes those tests without explicit marks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100