summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-03-09 10:38:08 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-03-09 10:38:08 +0100
commit98f8214fac4027c4b82e257b99af702236893d1f (patch)
tree0683053af81c1c830fd4201ef51b5c35d974479d
parent2ae8da3745decc6e7814f7ef41a309982e2114fb (diff)
downloadlogilab-common-98f8214fac4027c4b82e257b99af702236893d1f.tar.gz
[pytest] when -x option is given, stop on the first error even if there are multiple test directories
-rw-r--r--ChangeLog2
-rw-r--r--pytest.py28
2 files changed, 22 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 7f8c157..d2f1db3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@ ChangeLog for logilab.common
--
* date: new 'totime' function
* adbh, db, sqlgen modules moved to the new logilab-database package
+ * pytest: when -x option is given, stop on the first error even if
+ there are multiple test directories
2010-02-26 -- 0.48.1
* adbh: added dbport optional argument to [backup|restore]_commands
diff --git a/pytest.py b/pytest.py
index 6e1f432..bf546db 100644
--- a/pytest.py
+++ b/pytest.py
@@ -363,7 +363,8 @@ class PyTester(object):
if this_is_a_testdir(basename):
print "going into", dirname
# we found a testdir, let's explore it !
- self.testonedir(dirname, exitfirst)
+ if not self.testonedir(dirname, exitfirst):
+ break
dirs[:] = []
if self.report.ran == 0:
print "no test dir found testing here:", here
@@ -373,7 +374,11 @@ class PyTester(object):
self.testonedir(here)
def testonedir(self, testdir, exitfirst=False):
- """finds each testfile in the `testdir` and runs it"""
+ """finds each testfile in the `testdir` and runs it
+
+ return true when all tests has been executed, false if exitfirst and
+ some test has failed.
+ """
for filename in abspath_listdir(testdir):
if this_is_a_testfile(filename):
if self.options.exitfirst and not self.options.restart:
@@ -388,11 +393,11 @@ succeeded test file :", osp.join(os.getcwd(),testlib.FILE_RESTART)
# run test and collect information
prog = self.testfile(filename, batchmode=True)
if exitfirst and (prog is None or not prog.result.wasSuccessful()):
- break
+ return False
self.firstwrite = True
# clean local modules
remove_local_modules_from_sys(testdir)
-
+ return True
def testfile(self, filename, batchmode=False):
"""runs every test in `filename`
@@ -498,19 +503,25 @@ class DjangoTester(PyTester):
if skipped in dirs:
dirs.remove(skipped)
if 'tests.py' in files:
- self.testonedir(dirname, exitfirst)
+ if not self.testonedir(dirname, exitfirst):
+ break
dirs[:] = []
else:
basename = osp.basename(dirname)
if basename in ('test', 'tests'):
print "going into", dirname
# we found a testdir, let's explore it !
- self.testonedir(dirname, exitfirst)
+ if not self.testonedir(dirname, exitfirst):
+ break
dirs[:] = []
def testonedir(self, testdir, exitfirst=False):
- """finds each testfile in the `testdir` and runs it"""
+ """finds each testfile in the `testdir` and runs it
+
+ return true when all tests has been executed, false if exitfirst and
+ some test has failed.
+ """
# special django behaviour : if tests are splitted in several files,
# remove the main tests.py file and tests each test file separately
testfiles = [fpath for fpath in abspath_listdir(testdir)
@@ -524,9 +535,10 @@ class DjangoTester(PyTester):
# run test and collect information
prog = self.testfile(filename, batchmode=True)
if exitfirst and (prog is None or not prog.result.wasSuccessful()):
- break
+ return False
# clean local modules
remove_local_modules_from_sys(testdir)
+ return True
def testfile(self, filename, batchmode=False):