Skip to content

Instantly share code, notes, and snippets.

@con-f-use
Created September 14, 2016 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save con-f-use/bac4c22e019497ab7380d05297bbc748 to your computer and use it in GitHub Desktop.
Save con-f-use/bac4c22e019497ab7380d05297bbc748 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Let's call this file 'mymodule.py'
# When run from the 'shell application' created by setuptools,
#+only doctests for `main()` get run, while `to_be_tested()` is
#+ignored `mymoduleapp -test`.
# Testing for both functions works, when run direcly as shell
# script, e.g. as `./mymodule.py --test`
# Used python version: Python 2.7.12 (setuptools 20.7.0)
import sys
def to_be_tested():
'''\
>>> to_be_tested()
2
'''
return 1 # Would fail, but doesn't get tested
def main():
if '--test' in sys.argv: # Test all functions above
import doctest
doctest.testmod(verbose=True) # Doesn't work
exit(0)
if __name__ == '__main__':
main()
#!/usr/bin/python
from setuptools import setup
setup(
name = 'mymodule',
version = 1,
author_email = 'con-f-use@gmx.net',
py_modules = ['mymodule'],
entry_points='''
[console_scripts]
mymoduleapp=mymodule:main
'''
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment