diff options
author | pierre-yves david <pierre-yves.david@insa-lyon.fr> | 2008-06-30 08:54:12 +0200 |
---|---|---|
committer | pierre-yves david <pierre-yves.david@insa-lyon.fr> | 2008-06-30 08:54:12 +0200 |
commit | 880314b0830b7d411041ac6f8ab711c0a05c6e38 (patch) | |
tree | 3cb3bee4531939d04aa6344d782aea52c931dedb | |
parent | 4644566524fc9f5b569d627f99304767a08d245e (diff) | |
download | logilab-common-880314b0830b7d411041ac6f8ab711c0a05c6e38.tar.gz |
recognize testdir/testfile with regexps
-rw-r--r-- | pytest.py | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -65,10 +65,11 @@ pytest --coverage test_foo.py (only if logilab.devtools is available) """ -import os, sys +import os, sys, re import os.path as osp from time import time, clock + from logilab.common.fileutils import abspath_listdir from logilab.common import testlib import doctest @@ -148,18 +149,15 @@ else: +TESTFILE_RE = re.compile("^((unit)?test.*|smoketest)\.py$") def this_is_a_testfile(filename): """returns True if `filename` seems to be a test file""" - filename = osp.basename(filename) - return ((filename.startswith('unittest') - or filename.startswith('test') - or filename.startswith('smoketest')) - and filename.endswith('.py')) + return TESTFILE_RE.match(osp.basename(filename)) - +TESTDIR_RE = re.compile("^(unit)?tests?$") def this_is_a_testdir(dirpath): """returns True if `filename` seems to be a test directory""" - return osp.basename(dirpath) in ('test', 'tests', 'unittests') + return TESTDIR_RE.match(osp.basename(dirpath)) def load_pytest_conf(path, parser): @@ -306,12 +304,13 @@ class PyTester(object): if skipped in dirs: dirs.remove(skipped) basename = osp.basename(dirname) - if basename in ('test', 'tests'): + if this_is_a_testdir(basename): print "going into", dirname # we found a testdir, let's explore it ! self.testonedir(dirname, exitfirst) dirs[:] = [] if self.report.ran == 0: + print "no test dir found testing here:", here # if no test was found during the visit, consider # the local directory as a test directory even if # it doesn't have a traditional test directory name |