>>> sympy.test(sort=False)
or
$ bin/test --random
This is to make sure that the test are independent of each other. The motivation
to do this is that sometimes tests in sympy are failing if not executed in a
certain order, see [1].
[1] http://groups.google.com/group/sympy/browse_thread/thread/a0900b89e7b5000f
---
bin/test | 13 ++++++++++---
sympy/utilities/runtests.py | 17 +++++++++++++----
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/bin/test b/bin/test
index 5444667..d581e57 100755
--- a/bin/test
+++ b/bin/test
@@ -25,13 +25,20 @@ parser.add_option("--pdb", action="store_true", dest="pdb",
default=False, help="Run post mortem pdb on each failure")
parser.add_option("--no-colors", action="store_false", dest="colors",
default=True, help="Do not report colored [OK] and [FAIL]")
-parser.add_option("-k", dest="kw", help="only run tests matching the given keyword expression", metavar="KEYWORD", default="")
-parser.add_option("--tb", dest="tb", help="traceback verboseness (short/no) [default: %default]", metavar="TBSTYLE", default="short")
+parser.add_option("-k", dest="kw",
+ help="only run tests matching the given keyword expression",
+ metavar="KEYWORD", default="")
+parser.add_option("--tb", dest="tb",
+ help="traceback verboseness (short/no) [default: %default]",
+ metavar="TBSTYLE", default="short")
+parser.add_option("--random", action="store_false", dest="sort", default=True,
+ help="Run tests in random order instead of sorting them")
options, args = parser.parse_args()
ok = sympy.test(*args, **{"verbose": options.verbose, "kw": options.kw,
- "tb": options.tb, "pdb": options.pdb, "colors": options.colors})
+ "tb": options.tb, "pdb": options.pdb, "colors": options.colors,
+ "sort": options.sort})
if ok:
sys.exit(0)
else:
diff --git a/sympy/utilities/runtests.py b/sympy/utilities/runtests.py
index 92e1eeb..6ec7541 100644
--- a/sympy/utilities/runtests.py
+++ b/sympy/utilities/runtests.py
@@ -57,6 +57,8 @@ def test(*args, **kwargs):
"""
Run all tests containing any of the given strings in their path.
+ If sort=False, run them in random order (not default).
+
Warning: Tests in *very* deeply nested directories are not found.
Examples:
@@ -81,6 +83,7 @@ def test(*args, **kwargs):
kw = kwargs.get("kw", "")
post_mortem = kwargs.get("pdb", False)
colors = kwargs.get("colors", True)
+ sort = kwargs.get("sort", True)
r = PyTestReporter(verbose, tb, colors)
t = SymPyTests(r, kw, post_mortem)
if len(args) == 0:
@@ -89,10 +92,9 @@ def test(*args, **kwargs):
mypaths = []
for p in t.get_paths(dir='sympy'):
mypaths.extend(glob(p))
- mypaths = list(set(mypaths))
- mypaths.sort()
+ mypaths = set(mypaths)
t.add_paths([p for p in mypaths if any(a in p for a in args)])
- return t.test()
+ return t.test(sort=sort)
def doctest(*paths, **kwargs):
"""
@@ -194,12 +196,19 @@ def add_paths(self, paths):
else:
self._tests.extend(self.get_tests(path2))
- def test(self):
+ def test(self, sort=False):
"""
Runs the tests.
+ If sort=False run tests in random order.
+
Returns True if all tests pass, otherwise False.
"""
+ if sort:
+ self._tests.sort()
+ else:
+ from random import shuffle
+ shuffle(self._tests)
self._reporter.start()
for f in self._tests:
try:
--
1.6.4