zed icon indicating copy to clipboard operation
zed copied to clipboard

Add test discovery and runnables for Python files

Open JosephTLyons opened this issue 1 year ago • 1 comments

Check for existing issues

  • [X] Completed

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 avatar May 21 '24 04:05 JosephTLyons

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.

JosephTLyons avatar May 21 '24 05:05 JosephTLyons

@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.

ThomAub avatar Jun 03 '24 08:06 ThomAub

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).

rayduck avatar Jun 03 '24 16:06 rayduck

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

osiewicz avatar Jul 20 '24 09:07 osiewicz

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

lazarust avatar Jul 23 '24 01:07 lazarust

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

NeilRiver avatar Aug 10 '24 19:08 NeilRiver

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

r-egor avatar Aug 19 '24 14:08 r-egor

FYI @JosephTLyons @osiewicz @rayduck

Drogi programiście, możesz pozwolić lwiej części społeczności swobodnie zająć się tworzeniem testów, jeśli wypuścisz pytest.

Dear developer, you can free up the lion's share of the community to write tests if you release pytest.

BozhenaVlasova avatar Aug 28 '24 17:08 BozhenaVlasova