Mock command line arguments for Python script with `optparse`? -


a python script want use (called snakefood) run commandline , takes commandline arguments, eg:

sfood /path/to/my/project 

the parsing of commandline arguments happens in file called gendeps.py using optparse. however, want use snakefood module script. there way can somehow mock passing of commandline arguments snakefood or way of rewriting gendeps.py doesn't depend on optparse anymore?

you can assign new list sys.argv:

import sys  sys.argv = ['programname', '-iq', '-q', directory] gendeps.gendeps() 

optparse uses sys.argv[1:] input when no explicit arguments have been passed in.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -