summaryrefslogtreecommitdiffstats
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-06 13:37:45 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-06 13:37:45 (GMT)
commitff432e6f4ad8e4430ce984ec883a3d038e1c7ab9 (patch)
tree9e80574fb8d33086e2305fc5aba42d456f2068ca /Lib/doctest.py
parent72363031b9d2b382d6d8c8703f716da982dcbbdf (diff)
downloadcpython-ff432e6f4ad8e4430ce984ec883a3d038e1c7ab9.zip
cpython-ff432e6f4ad8e4430ce984ec883a3d038e1c7ab9.tar.gz
cpython-ff432e6f4ad8e4430ce984ec883a3d038e1c7ab9.tar.bz2
Patch #1663234: you can now run doctest on test files and modules
using "python -m doctest [-v] filename ...".
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 32d076a..31339ed 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -2630,8 +2630,23 @@ __test__ = {"_TestClass": _TestClass,
}
def _test():
- r = unittest.TextTestRunner()
- r.run(DocTestSuite())
+ testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-']
+ if len(testfiles) > 0:
+ for filename in testfiles:
+ if filename.endswith(".py"):
+ # This is a module -- insert its dir into sys.path and try to
+ # import it. If it is part of a package, that possibly won't work
+ # because of package imports.
+ dirname, filename = os.path.split(filename)
+ sys.path.insert(0, dirname)
+ m = __import__(filename[:-3])
+ del sys.path[0]
+ testmod(m)
+ else:
+ testfile(filename, module_relative=False)
+ else:
+ r = unittest.TextTestRunner()
+ r.run(DocTestSuite())
if __name__ == "__main__":
_test()