zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
45.64k stars 2.51k forks source link

Add test discovery and runnables for Python files #12080

Open JosephTLyons opened 3 months ago

JosephTLyons commented 3 months ago

Check for existing issues

Describe the feature

There are a load of python testing frameworks, but of those, the most popular are:

It would be great if we could offer testing support for both unittest and pytest, as I think that would cover most users. We should include commands to run all tests, for both frameworks, and to discover and run single tests, for both frameworks. All that being said, I'm not sure if our task infrastructure is really set up to handle being able to run tests from different testing frameworks. @osiewicz would know more.


Honorable mentions for Python testing frameworks go to ward - its modern, neat, and then one I reach for these days.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

JosephTLyons commented 3 months ago

After thinking about it, it seems like we should bake unittest testing into the zed python crate, since its part of the standard lib, and then offer pytest testing via an extension, since its a 3rd-party python package.

ThomAub commented 2 months ago

@JosephTLyons Should pytest be in an extension or could it be added to the current implementation of @rayduck ? I think in python pytest is the defacto solutions to testing.

rayduck commented 2 months ago

A python user is likely to go for pytest as the test runner instead of unittest, hence pytest support should be built-in to the python crate, just like how the non-standard lib pyright LSP is included.

Ideally, zed checks the project's venv for the presence of pytest (perhaps looking at pyproject.toml) and if found, runs that particular pytest so any plugin or user config is preserved. Otherwise, fallback to unittest support.

What I think may be missing is (1) using different test discovery rules (i.e what's in runnables.scm) conditionally or having additional tags like @run-pytest that somehow would not show up in the UI when pytest is not available (pytest's discovery ruleset is a superset of unittest's). @osiewicz do you reckon this is possible today?

Less importantly, (2) a solid detection of venv or conda envs (in the meantime, just let users specify a local config for which test runner to use).

osiewicz commented 1 month ago

Yep, we can now adjust tasks to "fit" user system configuration (e.g. installed test runners and so on). Looking at the venv may be a bit tricky, but doable

lazarust commented 1 month ago

+1 to adding pytest support! It would also be nice to be able to debug a test in the IDE

NeilRiver commented 2 weeks ago

oh damn! i'm ready to use zed in production today! give me pytest plz to be honest i don't know a single living person on this planet who uses unittest (qa) in python FYI @JosephTLyons

r-egor commented 1 week ago

FYI @JosephTLyons @osiewicz Please, don't forget. Proszę, nie zapomnijcie.