|
| 1 | +"""Test the automark_dependency option. |
| 2 | +""" |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
| 7 | +def test_not_set(ctestdir): |
| 8 | + """No pytest.ini file, e.g. automark_dependency is not set. |
| 9 | +
|
| 10 | + Since automark_dependency defaults to false and test_a is not |
| 11 | + marked, the outcome of test_a will not be recorded. As a result, |
| 12 | + test_b will be skipped due to a missing dependency. |
| 13 | + """ |
| 14 | + ctestdir.makepyfile(""" |
| 15 | + import pytest |
| 16 | +
|
| 17 | + def test_a(): |
| 18 | + pass |
| 19 | +
|
| 20 | + @pytest.mark.dependency(depends=["test_a"]) |
| 21 | + def test_b(): |
| 22 | + pass |
| 23 | + """) |
| 24 | + result = ctestdir.runpytest("--verbose", "-rs") |
| 25 | + result.assert_outcomes(passed=1, skipped=1, failed=0) |
| 26 | + result.stdout.fnmatch_lines(""" |
| 27 | + *::test_a PASSED |
| 28 | + *::test_b SKIPPED |
| 29 | + """) |
| 30 | + |
| 31 | + |
| 32 | +def test_set_false(ctestdir): |
| 33 | + """A pytest.ini is present, automark_dependency is set to false. |
| 34 | +
|
| 35 | + Since automark_dependency is set to false and test_a is not |
| 36 | + marked, the outcome of test_a will not be recorded. As a result, |
| 37 | + test_b will be skipped due to a missing dependency. |
| 38 | + """ |
| 39 | + ctestdir.makefile('.ini', pytest=""" |
| 40 | + [pytest] |
| 41 | + automark_dependency = false |
| 42 | + """) |
| 43 | + ctestdir.makepyfile(""" |
| 44 | + import pytest |
| 45 | +
|
| 46 | + def test_a(): |
| 47 | + pass |
| 48 | +
|
| 49 | + @pytest.mark.dependency(depends=["test_a"]) |
| 50 | + def test_b(): |
| 51 | + pass |
| 52 | + """) |
| 53 | + result = ctestdir.runpytest("--verbose", "-rs") |
| 54 | + result.assert_outcomes(passed=1, skipped=1, failed=0) |
| 55 | + result.stdout.fnmatch_lines(""" |
| 56 | + *::test_a PASSED |
| 57 | + *::test_b SKIPPED |
| 58 | + """) |
| 59 | + |
| 60 | + |
| 61 | +def test_set_true(ctestdir): |
| 62 | + """A pytest.ini is present, automark_dependency is set to false. |
| 63 | +
|
| 64 | + Since automark_dependency is set to true, the outcome of test_a |
| 65 | + will be recorded, even though it is not marked. As a result, |
| 66 | + test_b will be skipped due to a missing dependency. |
| 67 | + """ |
| 68 | + ctestdir.makefile('.ini', pytest=""" |
| 69 | + [pytest] |
| 70 | + automark_dependency = true |
| 71 | + """) |
| 72 | + ctestdir.makepyfile(""" |
| 73 | + import pytest |
| 74 | +
|
| 75 | + def test_a(): |
| 76 | + pass |
| 77 | +
|
| 78 | + @pytest.mark.dependency(depends=["test_a"]) |
| 79 | + def test_b(): |
| 80 | + pass |
| 81 | + """) |
| 82 | + result = ctestdir.runpytest("--verbose", "-rs") |
| 83 | + result.assert_outcomes(passed=2, skipped=0, failed=0) |
| 84 | + result.stdout.fnmatch_lines(""" |
| 85 | + *::test_a PASSED |
| 86 | + *::test_b PASSED |
| 87 | + """) |
0 commit comments