I often write self-test code at the bottom of a module, i.e.
if __name__ == '__main__':
.
.
.
I want to keep this in the module so that if I modify it I can still run self-test on it. The module is part of a package. So there are inter-package references that need to be resolved; but these are resolved differently if I'm importing the package versus running the module standalone.
I end up with a kludge like this at the top of my modules, which is certainly ugly and probably not 'pythonic':
if __name__ == '__main__':
from CovSample import CovSample
from ArrayByRow import ArrayByRow
else:
from CEOpt import CovSample
from CEOpt import ArrayByRow
This works - if I'm importing package CEOpt - the else-branch references work, and if I'm running standalone - the direct module name imports work. But it's not pretty I would like one import statement for the inter-package calls that still work in standalone module test. Is that possible?