-
Notifications
You must be signed in to change notification settings - Fork 92
Description
So around a month ago I read Hynek Schlawack nice article about testing and packaging, which also direct me to another article by Ionel MC. The main point of those articles are why it is important to move source code directory below src directory instead of inside the main directory. They argue that is better for testing and packaging.
Back then I would like to share this thought in here but I was reluctant as I wasn't completely get their point (but now I'm pretty much do). Until, just recently I'm having a testing problem with my project. Took me many painful hours for me to figure out what's wrong, basically I was testing the package import using monkeypatching. And no matter how I manipulate the sys.path and the environment the package is already imported before the test run. It took me many hours to understand that pytest traversing through the __init__.py that is above its path and execute them before running the actual test. Then I tried reading the articles by Hynek and Ionel again, and now I can appreciate their approach more.
Then I started restructure my project, move source code to src/project_name, move tests to main directory, update CI.yaml, MANIFEST.in, and setup.cfg. And the problem above is gone.
Before I submit this issue I checked if there is similar issue, and turns out @jaimergp has already mention it on #78 , and I have to say that I disagree with this statement
Ionel seems to steer more into the general web framework domain which is quite different from our current practices. (@dgasmith)
I believe that this apply to our current practice as well, and I think one of my favorite argument from Hynek is
Your tests do not run against the package as it will be installed by its users. They run against whatever the situation in your project directory is.
I hope that we can revisit this idea again, to avoid many potential problems in package testing.