diff --git a/src/_pytask/collect.py b/src/_pytask/collect.py index 7fd1dff92..d0773988d 100644 --- a/src/_pytask/collect.py +++ b/src/_pytask/collect.py @@ -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 {} diff --git a/tests/test_collect.py b/tests/test_collect.py index 9a10831a5..e69d65db0 100644 --- a/tests/test_collect.py +++ b/tests/test_collect.py @@ -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