Skip to content

Commit 2d5fcbe

Browse files
authored
ask the Pants PEX for its version in test framework (#15)
Query the Pants PEX for a specific major/minor version for its version instead of having the test hard-code the Pants versions. This means that the test will just discover whatever Pants version is in the relevant resolve automatically and is one less item to update when updating Pants versions.
1 parent 25069d3 commit 2d5fcbe

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/python/shoalsoft/pants_mcp_plugin/plugin_integration_test.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ def run_pants_without_waiting(
9999

100100

101101
@contextmanager
102-
def isolated_pants(pants_version_str: str):
103-
pants_version = Version(pants_version_str)
104-
pants_major_minor = f"{pants_version.major}.{pants_version.minor}"
102+
def isolated_pants(pants_major_minor: str):
103+
pants_major_minor_version = Version(pants_major_minor)
104+
assert (
105+
len(pants_major_minor_version.release) == 2
106+
), "Expected only major/minor version to be provided."
105107

106108
# Find the Python interpreter compatible with this version of Pants.
107109
py_version_for_pants_major_minor = (
108-
"3.11" if Version(pants_major_minor) >= Version("2.25") else "3.9"
110+
"3.11" if pants_major_minor_version >= Version("2.25") else "3.9"
109111
)
110112
python_path = python_interpreter_path(py_version_for_pants_major_minor)
111113
assert (
@@ -141,6 +143,17 @@ def isolated_pants(pants_version_str: str):
141143

142144
buildroot = (Path.cwd() / f"buildroot-{pants_major_minor}").resolve()
143145
buildroot.mkdir(parents=True)
146+
(buildroot / "BUILDROOT").touch()
147+
148+
# Determine the full version of the Pants used for the test.
149+
version_result = subprocess.run(
150+
[python_path, str(pants_pex_path), "--version"],
151+
env={"NO_SCIE_WARNING": "1"},
152+
capture_output=True,
153+
check=True,
154+
cwd=buildroot,
155+
)
156+
pants_version = Version(version_result.stdout.decode("utf-8").strip())
144157

145158
workdir_base = buildroot / ".pants.d" / "workdirs"
146159
workdir_base.mkdir(parents=True)
@@ -262,7 +275,7 @@ async def get_pants_target_resource(spec: str) -> dict[str, typing.Any]:
262275
assert test_tgt["address"] == "//:test_tgt"
263276

264277

265-
@pytest.mark.parametrize("pants_version_str", ["2.29.0a0"])
278+
@pytest.mark.parametrize("pants_version_str", ("2.29",))
266279
def test_mcp_server_tools(pants_version_str: str) -> None:
267280
with isolated_pants(pants_version_str) as context:
268281
sources = {

0 commit comments

Comments
 (0)