Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c3b6122

Browse files
committedFeb 4, 2024
Fix.
1 parent 0bff197 commit c3b6122

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed
 

‎src/_pytask/delayed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def pytask_execute_task(session: Session, task: PTask) -> None: # noqa: C901, P
7676
if isinstance(task, PTaskWithPath) and task.path in COLLECTED_TASKS:
7777
tasks = COLLECTED_TASKS.pop(task.path)
7878
name_to_function = parse_collected_tasks_with_task_marker(tasks)
79-
elif isinstance(task, PTask) and None in COLLECTED_TASKS:
79+
elif None in COLLECTED_TASKS:
8080
tasks = COLLECTED_TASKS.pop(None)
8181
name_to_function = parse_collected_tasks_with_task_marker(tasks)
8282
else:

‎tests/test_execute.py

+25-35
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ def task_example(
10041004

10051005

10061006
@pytest.mark.end_to_end()
1007-
def test_task_that_depends_on_delayed_task(tmp_path):
1007+
def test_task_that_depends_on_delayed_task(runner, tmp_path):
10081008
source = """
10091009
from typing_extensions import Annotated
10101010
from pytask import DirectoryNode, task
@@ -1024,12 +1024,10 @@ def task_depends(
10241024
"""
10251025
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
10261026

1027-
session = build(paths=tmp_path)
1028-
1029-
assert session.exit_code == ExitCode.OK
1030-
assert len(session.tasks) == 2
1031-
assert len(session.tasks[0].produces["return"]) == 2
1032-
assert len(session.tasks[1].depends_on["paths"]) == 2
1027+
result = runner.invoke(cli, [tmp_path.as_posix()])
1028+
assert result.exit_code == ExitCode.OK
1029+
assert "2 Collected tasks" in result.output
1030+
assert "2 Succeeded" in result.output
10331031

10341032

10351033
@pytest.mark.end_to_end()
@@ -1062,7 +1060,7 @@ def task_depends(
10621060

10631061

10641062
@pytest.mark.end_to_end()
1065-
def test_delayed_task_generation(tmp_path):
1063+
def test_delayed_task_generation(runner, tmp_path):
10661064
source = """
10671065
from typing_extensions import Annotated
10681066
from pytask import DirectoryNode, task
@@ -1087,18 +1085,16 @@ def task_copy(
10871085
"""
10881086
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
10891087

1090-
session = build(paths=tmp_path)
1091-
1092-
assert session.exit_code == ExitCode.OK
1093-
assert len(session.tasks) == 4
1094-
assert len(session.tasks[0].produces["return"]) == 2
1095-
assert len(session.tasks[1].depends_on["paths"]) == 2
1088+
result = runner.invoke(cli, [tmp_path.as_posix()])
1089+
assert result.exit_code == ExitCode.OK
1090+
assert "4 Collected tasks" in result.output
1091+
assert "4 Succeeded" in result.output
10961092
assert tmp_path.joinpath("a-copy.txt").exists()
10971093
assert tmp_path.joinpath("b-copy.txt").exists()
10981094

10991095

11001096
@pytest.mark.end_to_end()
1101-
def test_delayed_task_generation_with_generator(tmp_path):
1097+
def test_delayed_task_generation_with_generator(runner, tmp_path):
11021098
source = """
11031099
from typing_extensions import Annotated
11041100
from pytask import DirectoryNode, task
@@ -1125,18 +1121,16 @@ def task_copy(
11251121
"""
11261122
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
11271123

1128-
session = build(paths=tmp_path)
1129-
1130-
assert session.exit_code == ExitCode.OK
1131-
assert len(session.tasks) == 4
1132-
assert len(session.tasks[0].produces["return"]) == 2
1133-
assert len(session.tasks[1].depends_on["paths"]) == 2
1124+
result = runner.invoke(cli, [tmp_path.as_posix()])
1125+
assert result.exit_code == ExitCode.OK
1126+
assert "4 Collected tasks" in result.output
1127+
assert "4 Succeeded" in result.output
11341128
assert tmp_path.joinpath("a-copy.txt").exists()
11351129
assert tmp_path.joinpath("b-copy.txt").exists()
11361130

11371131

11381132
@pytest.mark.end_to_end()
1139-
def test_delayed_task_generation_with_single_function(tmp_path):
1133+
def test_delayed_task_generation_with_single_function(runner, tmp_path):
11401134
source = """
11411135
from typing_extensions import Annotated
11421136
from pytask import DirectoryNode, task
@@ -1160,17 +1154,15 @@ def task_copy(
11601154
"""
11611155
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
11621156

1163-
session = build(paths=tmp_path)
1164-
1165-
assert session.exit_code == ExitCode.OK
1166-
assert len(session.tasks) == 3
1167-
assert len(session.tasks[0].produces["return"]) == 1
1168-
assert len(session.tasks[1].depends_on["paths"]) == 1
1157+
result = runner.invoke(cli, [tmp_path.as_posix()])
1158+
assert result.exit_code == ExitCode.OK
1159+
assert "3 Collected tasks" in result.output
1160+
assert "3 Succeeded" in result.output
11691161
assert tmp_path.joinpath("a-copy.txt").exists()
11701162

11711163

11721164
@pytest.mark.end_to_end()
1173-
def test_delayed_task_generation_with_task_node(tmp_path):
1165+
def test_delayed_task_generation_with_task_node(runner, tmp_path):
11741166
source = """
11751167
from typing_extensions import Annotated
11761168
from pytask import DirectoryNode, TaskWithoutPath, task, PathNode
@@ -1196,12 +1188,10 @@ def task_depends(
11961188
"""
11971189
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
11981190

1199-
session = build(paths=tmp_path)
1200-
1201-
assert session.exit_code == ExitCode.OK
1202-
assert len(session.tasks) == 3
1203-
assert len(session.tasks[0].produces["return"]) == 1
1204-
assert len(session.tasks[1].depends_on["paths"]) == 1
1191+
result = runner.invoke(cli, [tmp_path.as_posix()])
1192+
assert result.exit_code == ExitCode.OK
1193+
assert "3 Collected tasks" in result.output
1194+
assert "3 Succeeded" in result.output
12051195
assert tmp_path.joinpath("a-copy.txt").exists()
12061196

12071197

‎tests/test_jupyter/test_task_generator.ipynb

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"@task()\n",
2827
"def task_create_files() -> Annotated[None, DirectoryNode(pattern=\"[ab].txt\")]:\n",
2928
" path = Path()\n",
3029
" path.joinpath(\"a.txt\").write_text(\"Hello, \")\n",

0 commit comments

Comments
 (0)
Please sign in to comment.