napari / cookiecutter-napari-plugin

Cookiecutter for napari plugins
BSD 3-Clause "New" or "Revised" License
67 stars 41 forks source link

Question: Why are tests shipped with plugin code #87

Closed haesleinhuepf closed 2 years ago

haesleinhuepf commented 2 years ago

Hi all,

this is just a question: I was wondering, why test-code is shipped/deployed with the napari-plugin according to the template? On Java island, we typically have two separate folders for production ("main") source files and "test" sources. Once one compiles a jar file for deployment, the test source are excluded. In that way, one can keep the shipped binary small. Github-CI also doesn't need the tests within the deployed file, because it builds from source anyway. In the napari cookiecutter template, the _tests folder lives within the production sources. I'm wondering why.

What's the benefits from shipping the tests with a plugin? Or is it possible to exclude test files from the deployment? Does that make sense? Any hints and links are welcome!

Thanks, Robert

tlambert03 commented 2 years ago

This is a matter of preference. In my other projects I actually leave tests outside of the source and don't include in sdist.

I believe @jni likes putting tests in sdist because it makes it very easy to test the pip installed package with pytest --pyargs. This was done here to mimic the napari layout, but it's equally valid to leave them outside.

tlambert03 commented 2 years ago

It's possible to exclude files from your sdist by modifying your MANIFEST.in. (Regardless of where they are in your package). Though, personally, I'd probably just move the tests folder rather than modify manifest

haesleinhuepf commented 2 years ago

Thanks for the feedback Talley @tlambert03 ! Was suspecting that tests were outside src in earlier versions of the cookiecutter template, because some of my napari-plugins show that layout. Ok, if there is no hard reason to have the tests inside, I may also move that directory out of some of my plugins. I came across that issue because calling pytest tests/test_something.py::test_something is easier to type than pytest my_complicated_package_name/_tests/test_something.py::test_something, especially using terminals that cannot auto-complete within folders (Windows) ;-)

Thanks again!

tlambert03 commented 2 years ago

If you don't know the k flag in pytest you may also like that

pytest -k test_something

https://docs.pytest.org/en/6.2.x/usage.html#specifying-tests-selecting-tests

(It's not strictly a function name, it's more powerful, but generally possible to just get a single test no matter where it's located)

haesleinhuepf commented 2 years ago

Oh, cool I didn't know that. Big thanks!