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
This commit is contained in:
Fred Drake 2004-12-21 23:46:34 +00:00
parent e57d7b179a
commit 7c404a4bf7
4 changed files with 21 additions and 0 deletions

View file

@ -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)