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
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 0a13d77..2708fc7 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -2328,6 +2328,8 @@
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 @@
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)