Good advice I guess? I'd rather see people using '-m' to advocate instead for better test execution instead of pip stuff.
If you use subpackaging correctly, with relative imports and the like, this flag really helps. If you're still dumping tests under a 'tests' directory at the root of the project in py3... don't do that.
Sure, use subpackaging! It's a great feature, and it's an easy concept:
root is for the top-level thing, anything adjacent should be for building it, supporting it outside it's code, etc. Tests are inherently code and should be treated as such imo.
inside that package, partition like Java does; you might hate that, but it makes sense... choose your verbiage, but I divide 'src' and 'test' as the two sub packages. They are merely namespace packages and don't really do much other than force this separation.
do everything else the same; use relative imports; never import test in 'src', but hey, now you can import from 'src' in 'test' because they share the same package root - no sys.path or trickery needed
if using unittest, TestSuite and the test runner utils always work for me, and 'just work'. Only use implicit namespaces? No problem. If pytest... ask yourself if you really need it, because pytest has it's own sys.path logic wholly based on __init__.py existence
launch your TestRunner or equivalent .py with the '-m' flag, remembering that it's module import syntax
profit
tell others
refactor legacy code that does trickery for the test suite
As to 'why it is bad', you're essentially creating a 'tests' top-level pseudo package that only weakly associates itself with it's source. If you and all the other 'tests' packages got together and had a party, you'd probably leave with someone else's source! It's just muddy and ugly, and outdated to professional development (imo).
2
u/cyanrave Nov 03 '19
Good advice I guess? I'd rather see people using '-m' to advocate instead for better test execution instead of pip stuff.
If you use subpackaging correctly, with relative imports and the like, this flag really helps. If you're still dumping tests under a 'tests' directory at the root of the project in py3... don't do that.