aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2004-12-21 23:46:34 +0000
committerFred Drake <fdrake@acm.org>2004-12-21 23:46:34 +0000
commit7c404a4bf7b9061ee013bef361b6eba951218d80 (patch)
tree921da1debae9f4ac526fc818426d6ba55896bb8f /Lib/doctest.py
parentThe changes to the stateful codecs in 2.4 resulted in StreamReader.readline() (diff)
downloadcpython-7c404a4bf7b9061ee013bef361b6eba951218d80.tar.gz
cpython-7c404a4bf7b9061ee013bef361b6eba951218d80.tar.bz2
cpython-7c404a4bf7b9061ee013bef361b6eba951218d80.zip
add __file__ to the globals available for tests loaded via DocFileSuite;
this is useful for locating supporting data files, just as it is in Python modules
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 0a13d77586a..2708fc7da06 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -2328,6 +2328,8 @@ def DocFileTest(path, module_relative=True, package=None,
globs=None, parser=DocTestParser(), **options):
if globs is None:
globs = {}
+ else:
+ globs = globs.copy()
if package and not module_relative:
raise ValueError("Package may only be specified for module-"
@@ -2337,6 +2339,8 @@ def DocFileTest(path, module_relative=True, package=None,
if module_relative:
package = _normalize_module(package)
path = _module_relative_path(package, path)
+ if "__file__" not in globs:
+ globs["__file__"] = path
# Find the file and read it.
name = os.path.basename(path)