Test runner: Ability to customize test command
Check for existing issues
- [X] Completed
Describe the feature
I'd like the ability to customize the test runner command so that it can display backtraces. Right now, when I click the ▷ symbol next to a Rust test, it will run
cargo test -p <crate> <testname> -- --nocapture
But it'd sure be nice to be able to add/remove flags, tmp env vars, etc.
If applicable, add mockups / screenshots to help present your vision of the feature
No response
I think you might be able to do this by creating a task and then adding "tags": ["rust-test"] to it.
See: Binding runnable tags to task templates in the docs.
Hello, could you mind tell how to add custom flag to rust-test, after reading the docs, I couldn't managed to do it. I use the follwing to test if the default task can be replaced by my definition, but the triangle button does the default task instead of my definition.
{
"label": "my rust test",
"command": "echo $ZED_CUSTOM_RUST_PACKAGE",
"tags": ["rust-test"]
}
And I have no idea of how to get the full name of current test function name.
I don't know how to replace my pytest command too. I tried using "python-test", "pytest", "pytest-test" and it still run the default command.
@Tom-Boscher There are different tags for different levels within the test file. There's also support for different frameworks.
You would want to specify either python-pytest-class or python-pytest-method.
Discoverable here: https://github.com/zed-industries/zed/blob/95a1a8632dc102eea6afe1c3a15be8df26e5bcbc/crates/languages/src/python.rs#L465
Thanks @joe-p , this helped me work around the issue in #29807 where the python toolchain selector no longer works. In tasks.json, for pytest you can do something like:
[
{
"label": "pytest runner",
"command": "pyenv activate your-python-env && pytest $ZED_CUSTOM_PYTHON_TEST_TARGET",
"tags": ["python-pytest-class", "python-pytest-method"]
}
]
Note you have to restart zed every time you change tasks.json for it to take effect.
Thank you @joe-p !
Here is what i use for rust test with backtrace:
.zed/tasks.json:
[
{
"label": "rust test with backtrace",
"command": "cargo test -p '$ZED_CUSTOM_RUST_PACKAGE' --test '$ZED_CUSTOM_RUST_TEST_FRAGMENT' -- --exact '$ZED_CUSTOM_RUST_TEST_NAME'",
"env": {
"RUST_BACKTRACE": "full"
},
"tags": ["rust-test"]
},
{
"label": "rust lib test with backtrace",
"command": "cargo test -p '$ZED_CUSTOM_RUST_PACKAGE' --lib '$ZED_CUSTOM_RUST_TEST_NAME'",
"env": {
"RUST_BACKTRACE": "full"
},
"tags": ["rust-test"]
}
]
With it you can run task: spawn command search for rust test with backtrace while the selection is inside some test and it will run it.
I'm trying to achieve the following snippet from VSCode's project settings.json file with my python project:
{
"python.testing.pytestArgs": [
"tests",
"--reuse-db",
"--disable-warnings",
"--ds=conf.settings.test"
],
}
Anyone know if this is possible in Zed?
@all-iver
Note you have to restart zed every time you change tasks.json for it to take effect.
This was an invaluable comment, thank you.