Index: Doc/library/doctest.rst =================================================================== --- Doc/library/doctest.rst (revision 79554) +++ Doc/library/doctest.rst (working copy) @@ -809,9 +809,9 @@ * If *module_relative* is ``True`` (the default), then *filename* specifies an OS-independent module-relative path. By default, this path is relative to the calling module's directory; but if the *package* argument is specified, then it - is relative to that package. To ensure OS-independence, *filename* should use - ``/`` characters to separate path segments, and may not be an absolute path - (i.e., it may not begin with ``/``). + is relative to that package. To ensure that doctests run on every machine, a + :exc:`ValueError` is raised if an absolute path is used when *module_relative* + is set. * If *module_relative* is ``False``, then *filename* specifies an OS-specific path. The path may be absolute or relative; relative paths are resolved with Index: Lib/doctest.py =================================================================== --- Lib/doctest.py (revision 79554) +++ Lib/doctest.py (working copy) @@ -355,21 +355,23 @@ finally: sys.stdout = save_stdout -# [XX] Normalize with respect to os.path.pardir? def _module_relative_path(module, path): + """Transform module-relative path to absolute""" if not inspect.ismodule(module): raise TypeError, 'Expected a module: %r' % module - if path.startswith('/'): - raise ValueError, 'Module-relative files may not have absolute paths' + if os.path.isabs(path): + raise ValueError('Absolute path specified as module-relative' + + 'path: ' + path) + path = os.path.normpath(path) # Find the base directory for the path. if hasattr(module, '__file__'): # A normal module/package - basedir = os.path.split(module.__file__)[0] + basedir = os.path.dirname(module.__file__) elif module.__name__ == '__main__': # An interactive session. if len(sys.argv)>0 and sys.argv[0] != '': - basedir = os.path.split(sys.argv[0])[0] + basedir = os.path.dirname(sys.argv[0]) else: basedir = os.curdir else: @@ -378,7 +380,7 @@ module + " (it has no __file__)") # Combine the base directory and the path. - return os.path.join(basedir, *(path.split('/'))) + return os.path.join(basedir, path) ###################################################################### ## 2. Example & DocTest Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (revision 79554) +++ Lib/test/test_doctest.py (working copy) @@ -2201,11 +2201,11 @@ optional `module_relative` parameter: >>> doctest.testfile('test_doctest.txt', globs=globs, - ... module_relative='test') + ... module_relative=True) TestResults(failed=0, attempted=2) >>> doctest.master = None # Reset master. -Verbosity can be increased with the optional `verbose` paremter: +Verbosity can be increased with the optional `verbose` parameter: >>> doctest.testfile('test_doctest.txt', globs=globs, verbose=True) Trying: