From 19c9a895d54306aaf2ecd5dd6147f0b7989eb04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= <jdavid.ibp@gmail.com> Date: Sun, 26 May 2013 13:49:08 +0200 Subject: [PATCH] tests: find out test modules automatically --- test/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index b224393..1cbb37d 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -31,23 +31,26 @@ These tests are run automatically with 'setup.py test', but can also be run manually. """ +from os import listdir +from os.path import dirname import sys import unittest -names = ['blob', 'commit', 'config', 'diff', 'index', 'note', 'oid', 'refs', - 'remote', 'repository', 'revwalk', 'signature', 'status', 'tag', - 'tree', 'treebuilder'] - def test_suite(): # Sometimes importing pygit2 fails, we try this first to get an # informative traceback. import pygit2 - # Check the test modules import correctly, to get a nice error if one - # does not. - modules = ['test.test_%s' % n for n in names] - for module in modules: - __import__(module) + + # Build the list of modules + modules = [] + for name in listdir(dirname(__file__)): + if name.startswith('test_') and name.endswith('.py'): + module = 'test.%s' % name[:-3] + # Check the module imports correctly, have a nice error otherwise + __import__(module) + modules.append(module) + # Go return unittest.defaultTestLoader.loadTestsFromNames(modules)