|
| 1 | +def test_show_only_active_fixtures(testdir): |
| 2 | + p = testdir.makepyfile(''' |
| 3 | + import pytest |
| 4 | + @pytest.fixture |
| 5 | + def _arg0(): |
| 6 | + """hidden arg0 fixture""" |
| 7 | + @pytest.fixture |
| 8 | + def arg1(): |
| 9 | + """arg1 docstring""" |
| 10 | + def test_arg1(arg1): |
| 11 | + pass |
| 12 | + ''') |
| 13 | + |
| 14 | + result = testdir.runpytest("--setup-only", p) |
| 15 | + assert result.ret == 0 |
| 16 | + |
| 17 | + result.stdout.fnmatch_lines([ |
| 18 | + '*SETUP F arg1*', |
| 19 | + '*test_arg1 fixtures: arg1', |
| 20 | + '*TEARDOWN F arg1*', |
| 21 | + ]) |
| 22 | + assert "_arg0" not in result.stdout.str() |
| 23 | + |
| 24 | + |
| 25 | +def test_show_different_scopes(testdir): |
| 26 | + p = testdir.makepyfile(''' |
| 27 | + import pytest |
| 28 | + @pytest.fixture |
| 29 | + def arg_function(): |
| 30 | + """function scoped fixture""" |
| 31 | + @pytest.fixture(scope='session') |
| 32 | + def arg_session(): |
| 33 | + """session scoped fixture""" |
| 34 | + def test_arg1(arg_session, arg_function): |
| 35 | + pass |
| 36 | + ''') |
| 37 | + |
| 38 | + result = testdir.runpytest("--setup-only", p) |
| 39 | + assert result.ret == 0 |
| 40 | + |
| 41 | + result.stdout.fnmatch_lines([ |
| 42 | + 'SETUP S arg_session*', |
| 43 | + '*SETUP F arg_function*', |
| 44 | + '*test_arg1 fixtures: arg_function, arg_session', |
| 45 | + '*TEARDOWN F arg_function*', |
| 46 | + 'TEARDOWN S arg_session*', |
| 47 | + ]) |
| 48 | + |
| 49 | + |
| 50 | +def test_show_nested_fixtures(testdir): |
| 51 | + testdir.makeconftest(''' |
| 52 | + import pytest |
| 53 | + @pytest.fixture(scope='session') |
| 54 | + def arg_same(): |
| 55 | + """session scoped fixture""" |
| 56 | + ''') |
| 57 | + p = testdir.makepyfile(''' |
| 58 | + import pytest |
| 59 | + @pytest.fixture(scope='function') |
| 60 | + def arg_same(arg_same): |
| 61 | + """function scoped fixture""" |
| 62 | + def test_arg1(arg_same): |
| 63 | + pass |
| 64 | + ''') |
| 65 | + |
| 66 | + result = testdir.runpytest("--setup-only", p) |
| 67 | + assert result.ret == 0 |
| 68 | + |
| 69 | + result.stdout.fnmatch_lines([ |
| 70 | + 'SETUP S arg_same*', |
| 71 | + '*SETUP F arg_same*', |
| 72 | + '*test_arg1 fixtures: arg_same', |
| 73 | + '*TEARDOWN F arg_same*', |
| 74 | + 'TEARDOWN S arg_same*', |
| 75 | + ]) |
| 76 | + |
| 77 | + |
| 78 | +def test_show_fixtures_with_autouse(testdir): |
| 79 | + p = testdir.makepyfile(''' |
| 80 | + import pytest |
| 81 | + @pytest.fixture |
| 82 | + def arg_function(): |
| 83 | + """function scoped fixture""" |
| 84 | + @pytest.fixture(scope='session', autouse=True) |
| 85 | + def arg_session(): |
| 86 | + """session scoped fixture""" |
| 87 | + def test_arg1(arg_function): |
| 88 | + pass |
| 89 | + ''') |
| 90 | + |
| 91 | + result = testdir.runpytest("--setup-only", p) |
| 92 | + assert result.ret == 0 |
| 93 | + |
| 94 | + result.stdout.fnmatch_lines([ |
| 95 | + 'SETUP S arg_session*', |
| 96 | + '*SETUP F arg_function*', |
| 97 | + '*test_arg1 fixtures: arg_function, arg_session', |
| 98 | + ]) |
| 99 | + |
| 100 | + |
| 101 | +def test_show_fixtures_with_parameters(testdir): |
| 102 | + testdir.makeconftest(''' |
| 103 | + import pytest |
| 104 | + @pytest.fixture(scope='session', params=['foo', 'bar']) |
| 105 | + def arg_same(): |
| 106 | + """session scoped fixture""" |
| 107 | + ''') |
| 108 | + p = testdir.makepyfile(''' |
| 109 | + import pytest |
| 110 | + @pytest.fixture(scope='function') |
| 111 | + def arg_other(arg_same): |
| 112 | + """function scoped fixture""" |
| 113 | + def test_arg1(arg_other): |
| 114 | + pass |
| 115 | + ''') |
| 116 | + |
| 117 | + result = testdir.runpytest("--setup-only", p) |
| 118 | + assert result.ret == 0 |
| 119 | + |
| 120 | + result.stdout.fnmatch_lines([ |
| 121 | + 'SETUP S arg_same?foo?', |
| 122 | + 'TEARDOWN S arg_same?foo?', |
| 123 | + 'SETUP S arg_same?bar?', |
| 124 | + 'TEARDOWN S arg_same?bar?', |
| 125 | + ]) |
| 126 | + |
| 127 | + |
| 128 | +def test_show_fixtures_with_parameter_ids(testdir): |
| 129 | + testdir.makeconftest(''' |
| 130 | + import pytest |
| 131 | + @pytest.fixture( |
| 132 | + scope='session', params=['foo', 'bar'], ids=['spam', 'ham']) |
| 133 | + def arg_same(): |
| 134 | + """session scoped fixture""" |
| 135 | + ''') |
| 136 | + p = testdir.makepyfile(''' |
| 137 | + import pytest |
| 138 | + @pytest.fixture(scope='function') |
| 139 | + def arg_other(arg_same): |
| 140 | + """function scoped fixture""" |
| 141 | + def test_arg1(arg_other): |
| 142 | + pass |
| 143 | + ''') |
| 144 | + |
| 145 | + result = testdir.runpytest("--setup-only", p) |
| 146 | + assert result.ret == 0 |
| 147 | + |
| 148 | + result.stdout.fnmatch_lines([ |
| 149 | + 'SETUP S arg_same?spam?', |
| 150 | + 'SETUP S arg_same?ham?', |
| 151 | + ]) |
0 commit comments