@@ -112,11 +112,16 @@ def _collect_from_tasks(session: Session) -> None:
112112 except (TypeError , OSError ):
113113 path = None
114114 else :
115- if path .name == "<stdin>" :
115+ if path and path .name == "<stdin>" :
116116 path = None # pragma: no cover
117117
118118 # Detect whether a path is defined in a Jupyter notebook.
119- if is_jupyter () and "ipykernel" in path .as_posix () and path .suffix == ".py" :
119+ if (
120+ is_jupyter ()
121+ and path
122+ and "ipykernel" in path .as_posix ()
123+ and path .suffix == ".py"
124+ ):
120125 path = None # pragma: no cover
121126
122127 name = raw_task .pytask_meta .name
@@ -209,7 +214,11 @@ def pytask_collect_task_protocol(
209214 return CollectionReport (outcome = CollectionOutcome .SUCCESS , node = task )
210215
211216 except Exception : # noqa: BLE001
212- task = Task (base_name = name , path = path , function = None )
217+ if path :
218+ task = Task (base_name = name , path = path , function = obj )
219+ else :
220+ task = TaskWithoutPath (name = name , function = obj )
221+
213222 return CollectionReport .from_exception (
214223 outcome = CollectionOutcome .FAIL , exc_info = sys .exc_info (), node = task
215224 )
@@ -463,7 +472,7 @@ def pytask_collect_log(
463472 if isinstance (report .node , PTask ):
464473 short_name = format_task_name (
465474 report .node , editor_url_scheme = "no_link"
466- )
475+ ). plain
467476 else :
468477 short_name = reduce_node_name (report .node , session .config ["paths" ])
469478 header = f"Could not collect { short_name } "
@@ -475,8 +484,11 @@ def pytask_collect_log(
475484
476485 console .print ()
477486
487+ assert report .exc_info
478488 console .print (
479- render_exc_info (* report .exc_info , session .config ["show_locals" ])
489+ render_exc_info (
490+ * report .exc_info , show_locals = session .config ["show_locals" ]
491+ )
480492 )
481493
482494 console .print ()
0 commit comments