From 3406ff2500371bdb307d6c94aa104403d2b18871 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 22 Nov 2015 10:03:13 -0500 Subject: Extend import_local_file so I can use a file in another directory. --- coverage/backward.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'coverage/backward.py') diff --git a/coverage/backward.py b/coverage/backward.py index 81ca342f..4fc72215 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: -- cgit v1.2.1