mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
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:
parent
e57d7b179a
commit
7c404a4bf7
4 changed files with 21 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue