Skip to content

pytest.mark.django_db does not isolate tests #461

Closed
@qwiglydee

Description

@qwiglydee

pytest version 3.0.6
pytest-django-3.1.2
django-1.10

settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR + '/var/db.sqlite'
    },
    'world': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'test',
        'HOST': '',
        'USER': 'postgres',  # need superuser to create db
        'TEST': {
            'NAME': 'test'
        }
    }
}

tests:

@pytest.mark.django_db
def test_1():
    models.Feature.objects.create(id=99999999, **dumb_attrs)


@pytest.mark.django_db
def test_2():
    models.Feature.objects.create(id=99999999, **dumb_attrs)

Running tests fails with IntegrityError.
After running created objects remain in database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions