@@ -366,7 +366,7 @@ def discover(self, start_dir, pattern, top_level_dir):
366366 self .assertTrue (program .failfast )
367367 self .assertTrue (program .catchbreak )
368368
369- def test_detect_module_clash (self ):
369+ def setup_module_clash (self ):
370370 class Module (object ):
371371 __file__ = 'bar/foo.py'
372372 sys .modules ['foo' ] = Module
@@ -393,7 +393,10 @@ def isdir(_):
393393 os .listdir = listdir
394394 os .path .isfile = isfile
395395 os .path .isdir = isdir
396+ return full_path
396397
398+ def test_detect_module_clash (self ):
399+ full_path = self .setup_module_clash ()
397400 loader = unittest .TestLoader ()
398401
399402 mod_dir = os .path .abspath ('bar' )
@@ -406,6 +409,25 @@ def isdir(_):
406409 )
407410 self .assertEqual (sys .path [0 ], full_path )
408411
412+ def test_module_symlink_ok (self ):
413+ full_path = self .setup_module_clash ()
414+
415+ original_realpath = os .path .realpath
416+
417+ mod_dir = os .path .abspath ('bar' )
418+ expected_dir = os .path .abspath ('foo' )
419+
420+ def cleanup ():
421+ os .path .realpath = original_realpath
422+ self .addCleanup (cleanup )
423+
424+ def realpath (path ):
425+ if path == os .path .join (mod_dir , 'foo.py' ):
426+ return os .path .join (expected_dir , 'foo.py' )
427+ return path
428+ os .path .realpath = realpath
429+ loader = unittest .TestLoader ()
430+ loader .discover (start_dir = 'foo' , pattern = 'foo.py' )
409431
410432 def test_discovery_from_dotted_path (self ):
411433 loader = unittest .TestLoader ()
0 commit comments