File: test_without_django_loaded.py

package info (click to toggle)
pytest-django 4.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 604 kB
  • sloc: python: 4,006; makefile: 39; sh: 17
file content (117 lines) | stat: -rw-r--r-- 2,561 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pytest


@pytest.fixture
def no_ds(monkeypatch) -> None:
    """Ensure DJANGO_SETTINGS_MODULE is unset"""
    monkeypatch.delenv("DJANGO_SETTINGS_MODULE")


pytestmark = pytest.mark.usefixtures("no_ds")


def test_no_ds(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        import os

        def test_env():
            assert 'DJANGO_SETTINGS_MODULE' not in os.environ

        def test_cfg(pytestconfig):
            assert pytestconfig.option.ds is None
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0


def test_database(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        import pytest

        @pytest.mark.django_db
        def test_mark():
            assert 0

        @pytest.mark.django_db(transaction=True)
        def test_mark_trans():
            assert 0

        def test_db(db):
            assert 0

        def test_transactional_db(transactional_db):
            assert 0
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0
    r.stdout.fnmatch_lines(["*4 skipped*"])


def test_client(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        def test_client(client):
            assert 0

        def test_admin_client(admin_client):
            assert 0
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0
    r.stdout.fnmatch_lines(["*2 skipped*"])


def test_rf(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        def test_rf(rf):
            assert 0
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0
    r.stdout.fnmatch_lines(["*1 skipped*"])


def test_settings(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        def test_settings(settings):
            assert 0
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0
    r.stdout.fnmatch_lines(["*1 skipped*"])


def test_live_server(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        def test_live_server(live_server):
            assert 0
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0
    r.stdout.fnmatch_lines(["*1 skipped*"])


def test_urls_mark(pytester: pytest.Pytester) -> None:
    pytester.makepyfile(
        """
        import pytest

        @pytest.mark.urls('foo.bar')
        def test_urls():
            assert 0
    """
    )
    r = pytester.runpytest_subprocess()
    assert r.ret == 0
    r.stdout.fnmatch_lines(["*1 skipped*"])