Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/_pytask/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def pytask_collect_task(
if (name.startswith("task_") or has_mark(obj, "task")) and callable(obj):
dependencies = parse_nodes(session, path, name, obj, depends_on)
products = parse_nodes(session, path, name, obj, produces)
if products == {}:
raise Exception("Tasks need to declare products.")

markers = obj.pytask_meta.markers if hasattr(obj, "pytask_meta") else []
kwargs = obj.pytask_meta.kwargs if hasattr(obj, "pytask_meta") else {}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,11 @@ def test_find_shortest_uniquely_identifiable_names_for_tasks(tmp_path):

result = _find_shortest_uniquely_identifiable_name_for_tasks(tasks)
assert result == expected


def test_task_has_no_produces_defined(tmp_path):
source = "def task_write_text(produces): pass"
tmp_path.joinpath("task_module.py").write_text(source)
session = main({"paths": tmp_path})
assert session.collection_reports[0].outcome == CollectionOutcome.FAILED
assert session.collection_reports[0].exc_info