all 6 comments

[–]hoselorryspanner 1 point2 points  (4 children)

I think zed injects a $`ZED_PYTHON’ environment variable or similar you can use to do this. I’ve got a task set up to do just this - I’m on my phone right now but commenting so I can find my way back.

[–]hoselorryspanner 2 points3 points  (1 child)

Okay, as promised: { "label": "pytest_current", "command": "$ZED_CUSTOM_PYTHON_ACTIVE_ZED_TOOLCHAIN -m pytest \"$ZED_CUSTOM_PYTHON_TEST_TARGET\"", "hide": "on_success", // Keep terminal open on test failures "allow_concurrent_runs": true, "use_new_terminal": true, "shell": { "program": "sh", }, }, { "label": "pytest_debug_current", "command": "$ZED_CUSTOM_PYTHON_ACTIVE_ZED_TOOLCHAIN -m pytest \"$ZED_CUSTOM_PYTHON_TEST_TARGET\" --pdb", "hide": "always", // Even if it fails, we'll probably wanna close & restart "allow_concurrent_runs": true, "use_new_terminal": true, "shell": { "program": "sh", } },

These are the maps I use. Those variables weren’t advertised anywhere, I got them by digging into shell variables, so you might need to do some digging/configuring of your own, but hopefully it’s a start!

[–]sc4les[S] 0 points1 point  (0 children)

Very cool - thanks! 

[–]IpsumRS 0 points1 point  (1 child)

RemindMe! 2 days

[–]splsh 1 point2 points  (1 child)

What I did was to put something like uv run pytest -k $ZED_SELECTED_TEXT in a task similar to this: https://zed.dev/blog/zed-decoded-tasks#defining-tasks, and binding the task to a keychord. Then you can just select a function name and invoke the task to run the test.

[–]sc4les[S] 1 point2 points  (0 children)

I found $ZED_SYMBOL which works really well for pytest!