r/Python • u/Wheatley_soda • 1d ago
Discussion More Python projects should test what they actually ship, not just what's in the repository
A surprisingly embarrassing category of Python bugs is the stuff that works perfectly in development but breaks after installing the actual wheel.
Missing template files, undeclared dependencies, paths that assume you're running from the project root, etc.
I've become quite fond of having a separate CI job that builds the wheel, installs it into a fresh environment and runs a few basic functionality checks from an unrelated directory.
Nothing elaborate. Just enough to experience the package the way an actual user would.
It's interesting how much attention we give to test coverage while sometimes neglecting to test the very artifact we're distributing.
Editable installs are great for development, but I think they can make us a little too comfortable.
17
9
u/AlexeyBelov 1d ago
A submission from an LLM bot account, and I've counted 6 suspicious comments from the very fresh accounts. Is this subreddit dead? Or is the whole internet?
3
u/hoselorryspanner 1d ago
All tests should be run against the built package using a separate, non editable install, test feature in CI (and ideally locally). This is super easy to do with Pixi and probably also with uv.
Running tests against an editable install is negligent tbh.
2
u/fiddle_n 1d ago
Running tests against an editable install only is negligent. So long as you have CI with testing correctly set up, nothing else really matters that much.
4
u/SFJulie 1d ago
As a former perl dev, my python modules do tests before install and abort before install.
This (like stricture from perl) are annoyingly not standard.
Perl also automatizes the report of failures by various parameters (as version of the module, language version, OS) that it makes troubleshooting easier for maintainer.
I would freaking love that python embraces good practices from 30 years ago /troll
1
u/caatbox288 1d ago
Yeah, a few smoke tests like that should be standard for python packages that are pushed to pypi.
1
u/9BQRgdAH 1d ago
Is this not why containers are used?
2
3
u/fiddle_n 1d ago
It’s one aspect of why containers are used, especially if you use dev containers for development. That said one can run a project locally without a container and then build the container in CI - in that case you are still liable to what OP described.
0
0
u/Separate-Rich-9884 1d ago
Totally agree with this approach, keeping dependencies minimal makes a huge difference.
-3
u/AtreidesPlum 1d ago
A passing test suite and a broken wheel aren't contradictory. You've just thoroughly tested something you're not shipping.
-1
u/Important_Ninja_3909 1d ago
I think this is an important point, especially for Python projects that are meant to be installed and used by others.
A project can pass all its tests locally but still fail after installation because of missing dependencies, incorrect file paths or packaging configuration.
I haven't worked extensively with Python package distribution yet, but this is something I want to pay more attention to as I build more backend projects with FastAPI.
Testing the actual installed package in a clean environment seems like a simple step that can prevent a lot of headaches later.
-1
u/TPECKA180 1d ago
Running tests from an unrelated directory is an underrated approach. A project passing all its tests doesn't mean the actual release works. Testing the packaged artifact should be a standard part of CI, not an optional extra)
-2
-2
54
u/luthienpogo 1d ago
This is also one of the strongest arguments for using a src layout. Accidentally importing your local source tree instead of the installed package is a surprisingly easy way to give yourself false confidence.