File: test_plugin.py

package info (click to toggle)
python-django-test-migrations 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 1,479; makefile: 26
file content (62 lines) | stat: -rw-r--r-- 1,767 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import re
import subprocess

from django_test_migrations.constants import MIGRATION_TEST_MARKER


def test_call_pytest_setup_plan():
    """Checks that module is registered and visible in the meta data."""
    output_text = subprocess.check_output(
        [
            'pytest',
            '--setup-plan',
            # We need this part because otherwise check fails with `1` code:
            '--cov-fail-under',
            '0',
        ],
        stderr=subprocess.STDOUT,
        universal_newlines=True,
        encoding='utf8',
    )

    assert 'migrator' in output_text
    assert 'migrator_factory' in output_text


def test_pytest_registers_marker():
    """Ensure ``MIGRATION_TEST_MARKER`` marker is registered."""
    output_text = subprocess.check_output(
        ['pytest', '--markers'],
        stderr=subprocess.STDOUT,
        universal_newlines=True,
        encoding='utf8',
    )

    assert MIGRATION_TEST_MARKER in output_text


def test_pytest_markers():
    """Ensure ``MIGRATION_TEST_MARKER`` markers are properly added."""
    output_text = subprocess.check_output(
        [
            'pytest',
            '--collect-only',
            # Collect only tests marked with ``MIGRATION_TEST_MARKER`` marker
            '-m',
            MIGRATION_TEST_MARKER,
            # We need this part because otherwise check fails with `1` code:
            '--cov-fail-under',
            '0',
        ],
        stderr=subprocess.STDOUT,
        universal_newlines=True,
        encoding='utf8',
    )

    search_result = re.search(
        r'(?P<selected_number>\d+)\s+selected',
        output_text,
    )
    assert search_result
    assert int(search_result.group('selected_number') or 0) > 0
    assert 'test_pytest_plugin' in output_text