pytest-dev / pytest-dev/pytest-django

Apply "django_db" mark to tests using the database

Open
#368 2 comments 0 reactions 0 assignees View on GitHub

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)

(based on http://doc.pytest.org/en/latest/example/markers.html#automatically-adding-markers-based-on-test-names)

This allows to run only tests not using the DB: py.test -m 'not django_db'

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.