11from __future__ import annotations
22
33import subprocess
4+ import sys
45import textwrap
56
67import pytest
910from tests .conftest import run_in_subprocess
1011
1112
12- @pytest .mark .parametrize ("module_name " , [True , False ])
13- def test_add_new_hook_via_cli (tmp_path , module_name ):
13+ @pytest .mark .parametrize ("hook_location " , ["hooks/hooks.py" , "hooks.hooks" ])
14+ def test_add_new_hook_via_cli (tmp_path , hook_location ):
1415 hooks = """
1516 import click
1617 from pytask import hookimpl
@@ -23,38 +24,24 @@ def pytask_extend_command_line_interface(cli):
2324 tmp_path .joinpath ("hooks" ).mkdir ()
2425 tmp_path .joinpath ("hooks" , "hooks.py" ).write_text (textwrap .dedent (hooks ))
2526
26- if module_name :
27- args = (
28- "uv" ,
29- "run" ,
30- "python" ,
31- "-m" ,
32- "pytask" ,
33- "build" ,
34- "--hook-module" ,
35- "hooks.hooks" ,
36- "--help" ,
37- )
38- else :
39- args = (
40- "uv" ,
41- "run" ,
42- "pytask" ,
43- "build" ,
44- "--hook-module" ,
45- "hooks/hooks.py" ,
46- "--help" ,
47- )
48-
27+ args = (
28+ sys .executable ,
29+ "-m" ,
30+ "pytask" ,
31+ "build" ,
32+ "--hook-module" ,
33+ hook_location ,
34+ "--help" ,
35+ )
4936 result = run_in_subprocess (args , cwd = tmp_path )
5037 assert result .exit_code == ExitCode .OK
5138 assert "--new-option" in result .stdout
5239
5340
54- @pytest .mark .parametrize ("module_name " , [True , False ])
55- def test_add_new_hook_via_config (tmp_path , module_name ):
41+ @pytest .mark .parametrize ("hook_location " , ["hooks/hooks.py" , "hooks.hooks" ])
42+ def test_add_new_hook_via_config (tmp_path , hook_location ):
5643 tmp_path .joinpath ("pyproject.toml" ).write_text (
57- "[tool.pytask.ini_options]\n hook_module = ['hooks/hooks.py ']"
44+ f "[tool.pytask.ini_options]\n hook_module = ['{ hook_location } ']"
5845 )
5946
6047 hooks = """
@@ -68,19 +55,7 @@ def pytask_extend_command_line_interface(cli):
6855 tmp_path .joinpath ("hooks" ).mkdir ()
6956 tmp_path .joinpath ("hooks" , "hooks.py" ).write_text (textwrap .dedent (hooks ))
7057
71- if module_name :
72- args = (
73- "uv" ,
74- "run" ,
75- "--no-project" ,
76- "python" ,
77- "-m" ,
78- "pytask" ,
79- "build" ,
80- "--help" ,
81- )
82- else :
83- args = ("uv" , "run" , "--no-project" , "pytask" , "build" , "--help" )
58+ args = (sys .executable , "-m" , "pytask" , "build" , "--help" )
8459
8560 result = run_in_subprocess (args , cwd = tmp_path )
8661 assert result .exit_code == ExitCode .OK
0 commit comments