File: test_03_runtime.py

package info (click to toggle)
pytest-dependency 0.5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: python: 1,542; makefile: 66; sh: 8
file content (40 lines) | stat: -rw-r--r-- 1,068 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
"""Using depends() to mark dependencies at runtime.
"""

import pytest


def test_skip_depend_runtime(ctestdir):
    """One test is skipped, other dependent tests are skipped as well.
    This also includes indirect dependencies.
    """
    ctestdir.makepyfile("""
        import pytest
        from pytest_dependency import depends

        @pytest.mark.dependency()
        def test_a():
            pass

        @pytest.mark.dependency()
        def test_b():
            pytest.skip("explicit skip")

        @pytest.mark.dependency()
        def test_c(request):
            depends(request, ["test_b"])
            pass

        @pytest.mark.dependency()
        def test_d(request):
            depends(request, ["test_a", "test_c"])
            pass
    """)
    result = ctestdir.runpytest("--verbose")
    result.assert_outcomes(passed=1, skipped=3, failed=0)
    result.stdout.re_match_lines(r"""
        .*::test_a PASSED
        .*::test_b SKIPPED(?:\s+\(.*\))?
        .*::test_c SKIPPED(?:\s+\(.*\))?
        .*::test_d SKIPPED(?:\s+\(.*\))?
    """)