diff --git a/poethepoet/task/base.py b/poethepoet/task/base.py index 147ec5e29..9f25374f5 100644 --- a/poethepoet/task/base.py +++ b/poethepoet/task/base.py @@ -104,7 +104,7 @@ def __init__( self._config = config self._is_windows = sys.platform == "win32" self.invocation = invocation - self.inheritance = inheritance or TaskInheritance(cwd=str(config.cwd)) + self.inheritance = inheritance or TaskInheritance(cwd=str(config.project_dir)) @classmethod def from_config( diff --git a/tests/fixtures/cwd_project/pyproject.toml b/tests/fixtures/cwd_project/pyproject.toml index 7c98f7ee0..eb760bd8a 100644 --- a/tests/fixtures/cwd_project/pyproject.toml +++ b/tests/fixtures/cwd_project/pyproject.toml @@ -1,3 +1,6 @@ +[tool.poe.tasks.default_pwd] +cmd = "poe_test_pwd" + [tool.poe.tasks.cwd] cmd = "poe_test_pwd" cwd = "./subdir/foo" diff --git a/tests/test_cmd_tasks.py b/tests/test_cmd_tasks.py index 6b12b07ab..8cdd7b125 100644 --- a/tests/test_cmd_tasks.py +++ b/tests/test_cmd_tasks.py @@ -78,6 +78,21 @@ def test_cmd_task_with_cwd_option_env(run_poe_subproc, poe_project_path): assert result.stderr == "" +def test_cmd_task_runs_in_project_root_by_default( + run_poe_subproc, poe_project_path, projects +): + result = run_poe_subproc( + "default_pwd", + project="cwd", + cwd=poe_project_path.joinpath( + "tests", "fixtures", "cwd_project", "subdir", "foo" + ), + ) + assert result.capture == "Poe => poe_test_pwd\n" + assert result.stdout == f"{projects['cwd']}\n" + assert result.stderr == "" + + def test_cmd_task_with_cwd_option_pwd(run_poe_subproc, poe_project_path): result = run_poe_subproc( "cwd_poe_pwd",