Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58237 > unrolled thread
| Started by | Göktuğ Kayaalp <self@gkayaalp.com> |
|---|---|
| First post | 2013-11-01 06:10 +0200 |
| Last post | 2013-11-01 06:10 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Testing python command line apps -- Running from within the projects w/o installing Göktuğ Kayaalp <self@gkayaalp.com> - 2013-11-01 06:10 +0200
| From | Göktuğ Kayaalp <self@gkayaalp.com> |
|---|---|
| Date | 2013-11-01 06:10 +0200 |
| Subject | Re: Testing python command line apps -- Running from within the projects w/o installing |
| Message-ID | <mailman.1907.1383279056.18130.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Fri, Nov 01, 2013 at 10:42:23AM +1100, Ben Finney wrote:
> Göktuğ Kayaalp <self@gkayaalp.com> 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ğ
Back to top | Article view | comp.lang.python
csiph-web