From c2b7e86845bf4fe5def3282d0157a8677b39faaa Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Wed, 7 Jun 2023 09:32:27 +0200 Subject: [PATCH] Make products mandatory? --- src/_pytask/collect.py | 2 ++ tests/test_collect.py | 8 ++++++++ 2 files changed, 10 insertions(+) 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