Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58237

Re: Testing python command line apps -- Running from within the projects w/o installing

Date 2013-11-01 06:10 +0200
From Göktuğ Kayaalp <self@gkayaalp.com>
Subject Re: Testing python command line apps -- Running from within the projects w/o installing
References <20131031201207.GA9547@proxima.centauri> <7w1u310zz4.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.1907.1383279056.18130.python-list@python.org> (permalink)

Show all headers | View raw


[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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web