@@ -23,6 +23,16 @@ def get_output(args: list[str]) -> str:
23
23
return out .getvalue ()
24
24
25
25
26
+ warns_cli_root_override = pytest .warns (
27
+ UserWarning , match = "root .. is overridden by the cli arg ."
28
+ )
29
+ warns_absolute_root_override = pytest .warns (
30
+ UserWarning , match = "absolute root path '.*' overrides relative_to '.*'"
31
+ )
32
+
33
+ exits_with_not_found = pytest .raises (SystemExit , match = "no version found for" )
34
+
35
+
26
36
def test_cli_find_pyproject (
27
37
wd : WorkDir , monkeypatch : pytest .MonkeyPatch , debug_mode : DebugMode
28
38
) -> None :
@@ -34,20 +44,17 @@ def test_cli_find_pyproject(
34
44
out = get_output ([])
35
45
assert out .startswith ("0.1.dev1+" )
36
46
37
- with pytest .warns (
38
- UserWarning , match = "absolute root path '%s' overrides relative_to '%s'"
39
- ):
40
- with pytest .raises (SystemExit , match = "no version found for" ):
41
- get_output (["--root=.." ])
47
+ with exits_with_not_found :
48
+ get_output (["--root=.." ])
42
49
43
50
wd .write (PYPROJECT_TOML , PYPROJECT_ROOT )
44
- with pytest . raises ( SystemExit , match = "no version found for" ) :
51
+ with exits_with_not_found :
45
52
print (get_output (["-c" , PYPROJECT_TOML ]))
46
53
47
- with pytest . raises ( SystemExit , match = "no version found for" ) :
54
+ with exits_with_not_found , warns_absolute_root_override :
48
55
49
56
get_output (["-c" , PYPROJECT_TOML , "--root=.." ])
50
57
51
- with pytest . warns ( UserWarning , match = "root .. is overridden by the cli arg ." ) :
58
+ with warns_cli_root_override :
52
59
out = get_output (["-c" , PYPROJECT_TOML , "--root=." ])
53
60
assert out .startswith ("0.1.dev1+" )
0 commit comments