Skip to content

Commit 24038dd

Browse files
committed
Add test ensuring that tracebacks are rendered with rich.
1 parent 568a433 commit 24038dd

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ channels:
55
- nodefaults
66

77
dependencies:
8-
- python=3.6
8+
- python
99
- pip
1010
- setuptools_scm
1111
- toml

src/pytask_parallel/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def _process_exception(
182182
traceback = Traceback.from_exception(*exc_info, show_locals=show_locals)
183183
segments = console.render(traceback, options=console_options)
184184
text = "".join(segment.text for segment in segments)
185-
return *exc_info[:2], text
185+
return (*exc_info[:2], text)
186186

187187

188188
class DefaultBackendNameSpace:

tests/test_execute.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ def myfunc():
119119
task = DummyTask(myfunc)
120120

121121
session = Session()
122-
session.config = {"n_workers": 2, "parallel_backend": parallel_backend}
122+
session.config = {
123+
"n_workers": 2,
124+
"parallel_backend": parallel_backend,
125+
"show_locals": False,
126+
}
123127

124128
with PARALLEL_BACKENDS[parallel_backend](
125129
max_workers=session.config["n_workers"]
@@ -235,3 +239,29 @@ def task_5():
235239
assert first_task_name.endswith("task_0") or first_task_name.endswith("task_3")
236240
last_task_name = session.execution_reports[-1].task.name
237241
assert last_task_name.endswith("task_2") or last_task_name.endswith("task_5")
242+
243+
244+
@pytest.mark.end_to_end
245+
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
246+
@pytest.mark.parametrize("show_locals", [True, False])
247+
def test_rendering_of_tracebacks_with_rich(
248+
runner, tmp_path, parallel_backend, show_locals
249+
):
250+
source = """
251+
import pytask
252+
253+
def task_raising_error():
254+
a = list(range(5))
255+
raise Exception
256+
"""
257+
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(source))
258+
259+
args = [tmp_path.as_posix(), "-n", "2", "--parallel-backend", parallel_backend]
260+
if show_locals:
261+
args.append("--show-locals")
262+
result = runner.invoke(cli, args)
263+
264+
assert result.exit_code == 1
265+
assert "───── Traceback" in result.output
266+
assert ("───── locals" in result.output) is show_locals
267+
assert ("[0, 1, 2, 3, 4]" in result.output) is show_locals

0 commit comments

Comments
 (0)