diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-11-22 10:03:13 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-11-22 10:03:13 -0500 |
commit | 5a38a3e5ff72fcd6fdb2e8b62345974eb96097da (patch) | |
tree | b6360fefa5d5572160f283b9d214b7ba416ce6e1 /coverage/backward.py | |
parent | 7d17d03a7465d48da6b7b4ae8ae4888b99d1e9fb (diff) | |
download | python-coveragepy-5a38a3e5ff72fcd6fdb2e8b62345974eb96097da.tar.gz |
Extend import_local_file so I can use a file in another directory.
Diffstat (limited to 'coverage/backward.py')
-rw-r--r-- | coverage/backward.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index 81ca342..4fc7221 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -151,11 +151,12 @@ except AttributeError: PYC_MAGIC_NUMBER = imp.get_magic() -def import_local_file(modname): +def import_local_file(modname, modfile=None): """Import a local file as a module. Opens a file in the current directory named `modname`.py, imports it - as `modname`, and returns the module object. + as `modname`, and returns the module object. `modfile` is the file to + import if it isn't in the current directory. """ try: @@ -163,7 +164,8 @@ def import_local_file(modname): except ImportError: SourceFileLoader = None - modfile = modname + '.py' + if modfile is None: + modfile = modname + '.py' if SourceFileLoader: mod = SourceFileLoader(modname, modfile).load_module() else: |