1
0
mirror of https://github.com/jbranchaud/til synced 2026-07-03 16:18:24 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
jbranchaud 1766e45134 Add Start The Debugger When A Test Errors as a Python TIL 2026-03-23 21:27:10 -05:00
jbranchaud c875652725 Add Add Default Task To List All Tasks as a Taskfile TIL 2026-03-23 21:12:44 -05:00
3 changed files with 82 additions and 1 deletions
+3 -1
View File
@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
_1764 TILs and counting..._
_1766 TILs and counting..._
See some of the other learning resources I work on:
@@ -1060,6 +1060,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Look Inside Pytest tmp_path](python/look-inside-pytest-tmp-path.md)
- [Override The Boolean Context Of A Class](python/override-the-boolean-context-of-a-class.md)
- [Parse Relative Time To datetime Object](python/parse-relative-time-to-datetime-object.md)
- [Start The Debugger When A Test Errors](python/start-the-debugger-when-a-test-errors.md)
- [Store And Access Immutable Data In A Tuple](python/store-and-access-immutable-data-in-a-tuple.md)
- [Test A Function With Pytest](python/test-a-function-with-pytest.md)
- [Use pipx To Install End User Apps](python/use-pipx-to-install-end-user-apps.md)
@@ -1578,6 +1579,7 @@ If you've learned something here, support my efforts writing daily TILs by
### Taskfile
- [Add Default Task To List All Tasks](taskfile/add-default-task-to-list-all-tasks.md)
- [Create Interactive Picker For Set Of Subtasks](taskfile/create-interactive-picker-for-set-of-subtasks.md)
- [Run A Task If It Meets Criteria](taskfile/run-a-task-if-it-meets-criteria.md)
@@ -0,0 +1,27 @@
# Start The Debugger When A Test Errors
While working on [some
tests](https://github.com/jbranchaud/build-an-llm-from-scratch/blob/main/tests/chapter_02/test_bpe_tokenizer.py)
for my Byte Pair Encoding tokenizer, I was running into an unexpected test
failure. To better understand what was going on, I needed to inspect the state
of the program around the time the code raised an exception.
Instead of needing to manually set a breakpoint at the correct spot to begin
debugging, I can run the test with the Pytest-supported `--pdb` flag. That's
short for _python debugger_.
> Start the interactive Python debugger on errors or KeyboardInterrupt
What this does during a test run is opens you up to the interactive Python
debugger at the exact moment an exception is raised. This gives you the ability
to inspect values of the program state at that point in execution which could
help inform the needed fix.
```bash
uv run pytest -vv --pdb -k "test_train_bpe"
```
There I am running a specific test that matches against `-k "test_train_bpe"`
and the python debugger will start up if there is an error.
See `uv run pytest --help` for more details.
@@ -0,0 +1,52 @@
# Add Default Task To List All Tasks
One thing I like about [`just`](https://github.com/casey/just) is that if you
run `just` by itself, the default behavior is to list out all the commands it
can run.
[Taskfile](https://github.com/go-task/task) technically does this as well, but
with a warning at the end:
```
task
task: Available tasks for this project:
* notes: Interactive picker for notes tasks
* notes:diff: Show uncommitted changes in notes
* notes:edit: All-in-one edit, commit, and push notes
* notes:log: Show recent commit history for notes
* notes:open: Opens NOTES.md (syncs latest changes first) in default editor
* notes:push: Commit and push changes to notes submodule
* notes:status: Check status of notes submodule
* notes:sync: Sync latest changes from the notes submodule
task: Task "default" does not exist
```
I prefer to tidy this up a little by adding `task --list` as the _default_ in my
`Taskfile.yml`.
```yml
default:
desc: Show available commands
cmds:
- task --list
```
Now when I run `task` with no arguments, I get this minutely nicer version:
```
task
Alias tip: t
task: [default] task --list
task: Available tasks for this project:
* default: Show available commands
* notes: Interactive picker for notes tasks
* notes:diff: Show uncommitted changes in notes
* notes:edit: All-in-one edit, commit, and push notes
* notes:log: Show recent commit history for notes
* notes:open: Opens NOTES.md (syncs latest changes first) in default editor
* notes:push: Commit and push changes to notes submodule
* notes:status: Check status of notes submodule
* notes:sync: Sync latest changes from the notes submodule
```
Notice there is no `task: Task "default" does not exist` warning at the end.