Testing python package bin scripts best practice -


myproject/     bin/         myscript     mypackage/         __init__.py         core.py         tests/             __init__.py             test_mypackage.py     setup.py 

what best way test script myscript?

from research, seems answer i've found write test in tests called test_myscript , use like

import subprocess  process = subprocess.popen('myscript arg1 arg2') print process.communicate() 

in test case run script , test results. there better way? or other suggestions different ways? , should put test suite in bin/tests or in mypackage/tests?

i don't believe there "best practices" put tests. see how many different opinions there: where python unit tests go?

i'd have 1 , tests directory on top-level, near bin , mypackage directories - as, example, django has.

for running bin script , getting results can use:

  • subprocess (as you've mentioned), using check_output:

    import subprocess output = subprocess.check_output("cat /etc/services", shell=true) 
  • scripttest module

    • was designed test command-line scripts - looks tool job
    • also see article
  • cli , it's cli.test module (haven't ever used personally)

hope helps.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -