File: migrations.py

package info (click to toggle)
python-pytest-djangoapp 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 396 kB
  • sloc: python: 1,116; makefile: 114; sh: 6
file content (30 lines) | stat: -rw-r--r-- 706 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest

from django import VERSION


@pytest.fixture()
def check_migrations(command_makemigrations):
    """Check if migrations are up to date (migration files exist for current models' state).

    Example::

        def test_this(check_migrations):
            result = check_migrations()

    :param app: Application name to check migrations for.

    """
    def check_migrations_(app: str = ''):
        if VERSION < (2, 0):
            raise Exception('Django 2.0+ required for checking migrations')

        try:
            command_makemigrations(app=app, args=['--check', '--dry-run'])

        except SystemExit:
            return False

        return True

    return check_migrations_