Skip to content

Commit 743ebd1

Browse files
authored
Fix crowding-out of tasks in table by skipped and persisted tasks. (#226)
1 parent e2812c2 commit 743ebd1

File tree

3 files changed

+98
-22
lines changed

3 files changed

+98
-22
lines changed

docs/source/changes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
1818
- :pull:`221` adds more test cases for parametrizations.
1919
- :pull:`222` adds an automated Github Actions job for creating a list pytask plugins.
2020
- :pull:`225` fixes a circular import noticeable in plugins created by :pull:`197`.
21+
- :pull:`226` fixes a bug where the number of items in the live table during the
22+
execution is not exhausted.
2123

2224

2325
0.1.8 - 2022-02-07

src/_pytask/live.py

+26-22
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,26 @@ def _generate_table(self, reduce_table: bool, sort_table: bool) -> Table | None:
182182
183183
"""
184184
n_reports_to_display = self._n_entries_in_table - len(self._running_tasks)
185+
186+
if self._verbose < 2:
187+
reports = [
188+
report
189+
for report in self._reports
190+
if report["outcome"]
191+
not in (
192+
TaskOutcome.SKIP,
193+
TaskOutcome.SKIP_UNCHANGED,
194+
TaskOutcome.SKIP_PREVIOUS_FAILED,
195+
TaskOutcome.PERSISTENCE,
196+
)
197+
]
198+
else:
199+
reports = self._reports
200+
185201
if not reduce_table:
186-
relevant_reports = self._reports
202+
relevant_reports = reports
187203
elif n_reports_to_display >= 1:
188-
relevant_reports = self._reports[-n_reports_to_display:]
204+
relevant_reports = reports[-n_reports_to_display:]
189205
else:
190206
relevant_reports = []
191207

@@ -198,26 +214,14 @@ def _generate_table(self, reduce_table: bool, sort_table: bool) -> Table | None:
198214
table.add_column("Task", overflow="fold")
199215
table.add_column("Outcome")
200216
for report in relevant_reports:
201-
if (
202-
report["outcome"]
203-
in (
204-
TaskOutcome.SKIP,
205-
TaskOutcome.SKIP_UNCHANGED,
206-
TaskOutcome.SKIP_PREVIOUS_FAILED,
207-
TaskOutcome.PERSISTENCE,
208-
)
209-
and self._verbose < 2
210-
):
211-
pass
212-
else:
213-
table.add_row(
214-
format_task_id(
215-
report["task"],
216-
editor_url_scheme=self._editor_url_scheme,
217-
short_name=True,
218-
),
219-
Text(report["outcome"].symbol, style=report["outcome"].style),
220-
)
217+
table.add_row(
218+
format_task_id(
219+
report["task"],
220+
editor_url_scheme=self._editor_url_scheme,
221+
short_name=True,
222+
),
223+
Text(report["outcome"].symbol, style=report["outcome"].style),
224+
)
221225
for task in self._running_tasks.values():
222226
table.add_row(
223227
format_task_id(

tests/test_live.py

+70
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,76 @@ def test_live_execution_displays_subset_of_table(capsys, tmp_path, n_entries_in_
205205
assert "│ ." in captured.out
206206

207207

208+
@pytest.mark.unit
209+
def test_live_execution_skips_do_not_crowd_out_displayed_tasks(capsys, tmp_path):
210+
path = tmp_path.joinpath("task_module.py")
211+
task = PythonFunctionTask(
212+
"task_example", path.as_posix() + "::task_example", path, lambda x: x
213+
)
214+
task.short_name = "task_module.py::task_example"
215+
216+
live_manager = LiveManager()
217+
live = LiveExecution(live_manager, 20, 1, "no_link")
218+
219+
live_manager.start()
220+
live.update_running_tasks(task)
221+
live_manager.stop()
222+
223+
# Test table with running task.
224+
captured = capsys.readouterr()
225+
assert "Task" in captured.out
226+
assert "Outcome" in captured.out
227+
assert "task_module.py::task_example" in captured.out
228+
assert "running" in captured.out
229+
230+
# Add one displayed reports and many more not displayed reports to crowd out the
231+
# valid one.
232+
successful_task = PythonFunctionTask(
233+
"task_success", path.as_posix() + "::task_success", path, lambda x: x
234+
)
235+
successful_task.short_name = "task_module.py::task_success"
236+
237+
tasks = []
238+
for i in range(25):
239+
skipped_task = PythonFunctionTask(
240+
f"task_skip_{i}", path.as_posix() + f"::task_skip_{i}", path, lambda x: x
241+
)
242+
skipped_task.short_name = f"task_module.py::task_skip_{i}"
243+
tasks.append(skipped_task)
244+
245+
live_manager.start()
246+
live.update_running_tasks(successful_task)
247+
for task in tasks:
248+
live.update_running_tasks(task)
249+
live_manager.stop()
250+
251+
captured = capsys.readouterr()
252+
assert "running" in captured.out
253+
assert "task_success" in captured.out
254+
for i in range(25):
255+
assert f"task_skip_{i}" in captured.out
256+
257+
live_manager.resume()
258+
report = ExecutionReport(
259+
task=successful_task, outcome=TaskOutcome.SUCCESS, exc_info=None
260+
)
261+
live.update_reports(report)
262+
for task in tasks:
263+
report = ExecutionReport(task=task, outcome=TaskOutcome.SKIP, exc_info=None)
264+
live.update_reports(report)
265+
live_manager.stop()
266+
267+
# Test final table with reported outcome.
268+
captured = capsys.readouterr()
269+
assert "Task" in captured.out
270+
assert "Outcome" in captured.out
271+
assert "task_module.py::task_example" in captured.out
272+
assert "task_module.py::task_success" in captured.out
273+
assert "running" in captured.out
274+
assert TaskOutcome.SUCCESS.symbol in captured.out
275+
assert "task_skip" not in captured.out
276+
277+
208278
@pytest.mark.end_to_end
209279
def test_full_execution_table_is_displayed_at_the_end_of_execution(tmp_path, runner):
210280
source = """

0 commit comments

Comments
 (0)