|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import pytest |
16 | | -from pants.engine.internals.native_engine import Address |
| 16 | +from pants.backend.python.goals.pytest_runner import PytestPluginSetup |
| 17 | +from pants.engine.internals.native_engine import Address, EMPTY_DIGEST |
17 | 18 | from pants.testutil.rule_runner import RuleRunner |
18 | 19 |
|
19 | 20 | from pack_metadata.python_rules.python_path_rules import ( |
20 | 21 | PackPythonPath, |
21 | 22 | PackPythonPathRequest, |
| 23 | + PytestPackTestRequest, |
22 | 24 | ) |
23 | 25 |
|
24 | 26 |
|
@@ -120,5 +122,48 @@ def test_get_extra_sys_path_for_pack_dependencies( |
120 | 122 | assert pack_python_path.entries == expected |
121 | 123 |
|
122 | 124 |
|
123 | | -def test_inject_extra_sys_path_for_pack_tests(rule_runner: RuleRunner) -> None: |
124 | | - pass |
| 125 | +@pytest.mark.xfail(raises=AttributeError, reason="Not implemented in pants yet.") |
| 126 | +@pytest.mark.parametrize( |
| 127 | + "address,expected", |
| 128 | + ( |
| 129 | + ( |
| 130 | + Address("packs/foo/tests", relative_file_path="test_get_bar_action.py"), |
| 131 | + ("packs/foo/actions",), |
| 132 | + ), |
| 133 | + ( |
| 134 | + Address("packs/foo/tests", relative_file_path="test_get_baz_action.py"), |
| 135 | + ("packs/foo/actions",), |
| 136 | + ), |
| 137 | + ( |
| 138 | + Address( |
| 139 | + "packs/dr_seuss/tests", |
| 140 | + relative_file_path="test_get_from_actions_lib_action.py", |
| 141 | + ), |
| 142 | + ("packs/dr_seuss/actions", "packs/dr_seuss/actions/lib"), |
| 143 | + ), |
| 144 | + ( |
| 145 | + Address( |
| 146 | + "packs/shards/tests", |
| 147 | + relative_file_path="test_get_from_pack_lib_action.py", |
| 148 | + ), |
| 149 | + ("packs/shards/actions", "packs/shards/lib"), |
| 150 | + ), |
| 151 | + ( |
| 152 | + Address( |
| 153 | + "packs/shards/tests", relative_file_path="test_horn_eater_sensor.py" |
| 154 | + ), |
| 155 | + ("packs/shards/sensors", "packs/shards/lib"), |
| 156 | + ), |
| 157 | + ( |
| 158 | + Address("packs/metals/tests", relative_file_path="test_fly_action.py"), |
| 159 | + ("packs/metals/actions/mist_born", "packs/metals/actions"), |
| 160 | + ), |
| 161 | + ), |
| 162 | +) |
| 163 | +def test_inject_extra_sys_path_for_pack_tests( |
| 164 | + rule_runner: RuleRunner, address: Address, expected: tuple[str, ...] |
| 165 | +) -> None: |
| 166 | + target = rule_runner.get_target(address) |
| 167 | + result = rule_runner.request(PytestPluginSetup, (PytestPackTestRequest(target),)) |
| 168 | + assert result.digest == EMPTY_DIGEST |
| 169 | + assert result.extra_sys_path == expected |
0 commit comments