Skip to content

Commit ae7231d

Browse files
authored
Reset class variables of ExecutionReport and Traceback. (#588)
1 parent 096cdfd commit ae7231d

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

docs/source/changes.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2626
- {pull}`579` fixes an interaction with `--pdb` and `--trace` and task that return. The
2727
debugging modes swallowed the return and `None` was returned. Closes {issue}`574`.
2828
- {pull}`581` simplifies the code for tracebacks and unpublishes some utility functions.
29+
- {pull}`586` improves linting.
30+
- {pull}`587` improves typing of `capture.py`.
31+
- {pull}`588` resets class variables of `ExecutionReport` and `Traceback`.
2932

3033
## 0.4.6 - 2024-03-13
3134

src/_pytask/logging.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from rich.text import Text
1616

1717
import _pytask
18+
from _pytask.capture_utils import ShowCapture
1819
from _pytask.console import IS_WINDOWS_TERMINAL
1920
from _pytask.console import console
2021
from _pytask.pluginmanager import hookimpl
@@ -67,7 +68,7 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
6768
@hookimpl
6869
def pytask_post_parse(config: dict[str, Any]) -> None:
6970
# Set class variables on traceback object.
70-
Traceback.show_locals = config["show_locals"]
71+
Traceback._show_locals = config["show_locals"]
7172
# Set class variables on Executionreport.
7273
ExecutionReport.editor_url_scheme = config["editor_url_scheme"]
7374
ExecutionReport.show_capture = config["show_capture"]
@@ -124,6 +125,15 @@ def pytask_log_session_footer(
124125
console.rule(message, style=outcome.style)
125126

126127

128+
@hookimpl
129+
def pytask_unconfigure() -> None:
130+
"""Reset class variables."""
131+
Traceback._show_locals = False
132+
ExecutionReport.editor_url_scheme = "file"
133+
ExecutionReport.show_capture = ShowCapture.ALL
134+
ExecutionReport.show_locals = False
135+
136+
127137
_TIME_UNITS: list[_TimeUnit] = [
128138
_TimeUnit(singular="day", plural="days", short="d", in_seconds=86400),
129139
_TimeUnit(singular="hour", plural="hours", short="h", in_seconds=3600),

src/_pytask/traceback.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import pluggy
1515
from attrs import define
16+
from attrs import field
1617
from rich.traceback import Traceback as RichTraceback
1718

1819
import _pytask
@@ -45,14 +46,19 @@
4546
@define
4647
class Traceback:
4748
exc_info: OptionalExceptionInfo
49+
show_locals: bool = field()
4850

49-
show_locals: ClassVar[bool] = False
51+
_show_locals: ClassVar[bool] = False
5052
suppress: ClassVar[tuple[Path, ...]] = (
5153
_PLUGGY_DIRECTORY,
52-
TREE_UTIL_LIB_DIRECTORY,
5354
_PYTASK_DIRECTORY,
55+
TREE_UTIL_LIB_DIRECTORY,
5456
)
5557

58+
@show_locals.default
59+
def _show_locals_default(self) -> bool:
60+
return self._show_locals
61+
5662
def __rich_console__(
5763
self, console: Console, console_options: ConsoleOptions
5864
) -> RenderResult:
@@ -68,7 +74,7 @@ def __rich_console__(
6874
yield filtered_exc_info[2]
6975
else:
7076
yield RichTraceback.from_exception(
71-
*filtered_exc_info, show_locals=self.show_locals
77+
*filtered_exc_info, show_locals=self._show_locals
7278
)
7379

7480

tests/test_traceback.py

+10
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ def test_render_traceback_with_string_traceback():
5050
traceback = Traceback((Exception, Exception("Help"), "String traceback."))
5151
rendered = render_to_string(traceback, console)
5252
assert "String traceback." in rendered
53+
54+
55+
@pytest.mark.unit()
56+
def test_passing_show_locals():
57+
traceback = Traceback(
58+
(Exception, Exception("Help"), "String traceback."), show_locals=True
59+
)
60+
assert traceback.show_locals is True
61+
# Also tests that the class variable has been reset.
62+
assert traceback._show_locals is False

0 commit comments

Comments
 (0)