@@ -381,12 +381,15 @@ def trace_dispatch(self, *args):
381381 sys .stdout = save_stdout
382382
383383# [XX] Normalize with respect to os.path.pardir?
384- def _module_relative_path (module , path ):
384+ def _module_relative_path (module , test_path ):
385385 if not inspect .ismodule (module ):
386386 raise TypeError ('Expected a module: %r' % module )
387- if path .startswith ('/' ):
387+ if test_path .startswith ('/' ):
388388 raise ValueError ('Module-relative files may not have absolute paths' )
389389
390+ # Normalize the path. On Windows, replace "/" with "\".
391+ test_path = os .path .join (* (test_path .split ('/' )))
392+
390393 # Find the base directory for the path.
391394 if hasattr (module , '__file__' ):
392395 # A normal module/package
@@ -398,13 +401,19 @@ def _module_relative_path(module, path):
398401 else :
399402 basedir = os .curdir
400403 else :
404+ if hasattr (module , '__path__' ):
405+ for directory in module .__path__ :
406+ fullpath = os .path .join (directory , test_path )
407+ if os .path .exists (fullpath ):
408+ return fullpath
409+
401410 # A module w/o __file__ (this includes builtins)
402411 raise ValueError ("Can't resolve paths relative to the module "
403412 "%r (it has no __file__)"
404413 % module .__name__ )
405414
406- # Combine the base directory and the path.
407- return os .path .join (basedir , * ( path . split ( '/' )) )
415+ # Combine the base directory and the test path.
416+ return os .path .join (basedir , test_path )
408417
409418######################################################################
410419## 2. Example & DocTest
0 commit comments