It seems to me like if you have a reproducible test case, then you should ask in setuptools’ ticket tracker first, and then if there is still no answer you might want to ask build’s, but as of now I highly doubt that it is related to build:
I can confirm. To the best of my knowledge, what you are doing is correct, and there is a discrepancy that I can not explain. I do not see why tests/test_hello.py is correctly excluded when running python setup.py sdist but wrongly included when running python -m build.
I can’t reproduce — in my case both the tarball contents and SOURCES.txt are identical.
For a start, try python -m build -n. Build defaults to using a virtual environment for builds, and -n disables that. This should tell us whether it’s something on your system that’s affecting it: possibly a different setuptools version or some plugin.
It might have something to do with one of the builds triggering the revised include/exclude behavior when using an implict (flat) layout, as opposed to the recommend src layout. With this behavior, tests will be excluded by default, without the need for custom configuration. See, e.g. here. Or it could be the different version in the build vs. working environment, as others mentioned, or another factor. Also, did you check the wheel MANIFEST and contents? I’d trust it over the sdist…
Also, for completeness, what’s the contents of your pyproject.toml (FWIW, most modern projects should generally configure all of that declarativly in pyproject.toml and dump the setup.py, or at the very least move it to setup.cfg and have a stub setup.py).
The following pyproject.toml is what you should probably start with, as it includes both the required [build-system] block and the metadata and config replacing your setup.py above:
In general, if you use the same version of setuptools, python setup.py sdist should be pretty similar to python -m build --sdist (except when something gets cached accidentally).
But please note that find_packages(exclude=...) is not a direct indicative of what goes in the sdist. This configuration will rather interfere what goes on the wheel. If you are not using a plugin like setuptools-scm (or configuring a MANIFEST.in) , setuptools will fallback to a default set of files that might automatically include docs, tests, etc…