Skip to content

Instantly share code, notes, and snippets.

@petrblahos
Created January 15, 2013 19:21
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 petrblahos/4541213 to your computer and use it in GitHub Desktop.
Save petrblahos/4541213 to your computer and use it in GitHub Desktop.
pysktest1/tests/__init__.py
import sys
import unittest
class _WritelnDecorator(object):
"""Used to decorate file-like objects with a handy 'writeln' method"""
def __init__(self,stream):
self.stream = stream
def __getattr__(self, attr):
if attr in ('stream', '__getstate__'):
raise AttributeError(attr)
return getattr(self.stream,attr)
def writeln(self, arg=None):
if arg:
self.write(arg)
self.write('\n') # text-mode streams translate to \r\n if needed
def runtests():
tests = unittest.defaultTestLoader.discover(".") #Python 2.7 or better?!?
sys.stderr.write("UNIT TESTS:")
res = unittest.TextTestResult(stream=_WritelnDecorator(sys.stderr), descriptions=True, verbosity=1)
tests.run(res)
if res.wasSuccessful():
print "TESTS PASSED"
else:
print "SOME TESTS HAVE FAILED"
res.printErrors()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment