On Fri, Nov 01, 2013 at 10:42:23AM +1100, Ben Finney wrote: > Göktuğ Kayaalp <[email protected]> writes: > > > I'm using python to write command line apps from time to time. I > > wonder *what is the conventional way to test-run these apps from > > within the project itself, while developing, without installing*. > > [So] the advice for testing the program's main module specialises to: Keep > the body of “if __name__ == '__main__':” to an absolute minimum. Put all > of the set-up and process-end functionality into discrete functions with > discrete purposes, clear return values, and explicit parameters.
This is usually the way I write my modules, and I do test my command
line interfaces in a manner similar to your example. But what I was
asking is how to actually run these programs within a command shell
session and test them in a more *tangible* fashion:
(app) ~/app% ls
scripts/ app/ tests/ setup.py LICENSE README
(app) ~/app% cat scripts/app
#!/usr/bin/env python
from app import main; import sys
if __name__ == '__main__': exit(main.main(sys.argv[1:]))
(app) ~/app% scripts/app -CMdargs -- testdata.txt
Traceback (most recent call last):
File "app", line 1, in <module>
from app import main; import sys
ImportError: no module named 'app'
I write a secondary script, 'app_tester', which is similar to 'app', but
before running app.main.main, it inserts ~/app to the front of sys.path.
What I want to find out is how to achieve this w/o having a secondary
script that manipulates the path.
> This is adapted from an article by Guido van Rossum
> <URL:http://www.artima.com/weblogs/viewpost.jsp?thread=4829>.
I'll definitely give this a read.
> [...]
cheers,
göktuğ
signature.asc
Description: Digital signature
-- https://mail.python.org/mailman/listinfo/python-list
