Created
January 15, 2013 19:21
-
-
Save petrblahos/4541213 to your computer and use it in GitHub Desktop.
pysktest1/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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