Skip to content

Commit

Permalink
Merge pull request #28 from enthought/enh-exit-code-for-tests
Browse files Browse the repository at this point in the history
Adding exit code that indicates success of tests when run from setup.py
  • Loading branch information
cfarrow committed Mar 12, 2014
2 parents 0462686 + 5eaf33a commit c3cc459
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions comtypes/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def run(self, test, skipped):


def run_tests(package, mask, verbosity, search_leaks):
""" Run tests for package and return True on failure, False otherwise """
skipped, testcases = get_tests(package, mask, verbosity)
runner = TestRunner(verbosity=verbosity)

Expand All @@ -199,7 +200,7 @@ def run_tests(package, mask, verbosity, search_leaks):
for t in testcases:
test_with_refcounts(runner, verbosity, t)

return bool(result.errors)
return bool(result.errors) or bool(result.failures)

class BasicTestRunner:
def run(self, test):
Expand All @@ -208,6 +209,7 @@ def run(self, test):
return result

def run(args = []):
""" Run tests and return True on failure, False otherwise """
try:
opts, args = getopt.getopt(args, "rqvu:")
except getopt.error:
Expand Down Expand Up @@ -235,4 +237,4 @@ def run(args = []):
mask = args[0]

import comtypes.test
run_tests(comtypes.test, mask, verbosity, search_leaks)
return run_tests(comtypes.test, mask, verbosity, search_leaks)
17 changes: 11 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def initialize_options(self):
self.use_resources = ""
self.refcounts = False
self.tests = "comtypes.test"
self.failure = False

def finalize_options(self):
if self.refcounts and not hasattr(sys, "gettotalrefcount"):
Expand All @@ -55,15 +56,15 @@ def run(self):
comtypes.test.register_server(source_dir)

comtypes.test.use_resources.extend(self.use_resources)

for name in self.tests:
package = __import__(name, globals(), locals(), ['*'])
sys.stdout.write("Testing package %s %s\n"
% (name, (sys.version, sys.platform, os.name)))
comtypes.test.run_tests(package,
"test_*.py",
self.verbose,
self.refcounts)
package_failure = comtypes.test.run_tests(package,
"test_*.py",
self.verbose,
self.refcounts)
self.failure = self.failure or package_failure

classifiers = [
'Development Status :: 4 - Beta',
Expand Down Expand Up @@ -140,4 +141,8 @@ def read_version():
)

if __name__ == '__main__':
setup(**setup_params)
dist = setup(**setup_params)
# Exit with a failure code if only running the tests and they failed
if dist.commands == ['test']:
command = dist.command_obj['test']
sys.exit(command.failure)

0 comments on commit c3cc459

Please sign in to comment.