summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-10-23 17:15:05 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-10-23 17:15:05 (GMT)
commit6c6b3f770d0b54eeb3e42b38e1fe5d893c38dd6e (patch)
tree6f6f93e241e5fe83fb3822d92eaa80f2a5f862df /Lib/unittest/test
parent3d3e1ba8ac9d759394a76a3da4c47247b3120be3 (diff)
parentd5d0bc35adc6c043d5985152451505e70d869341 (diff)
downloadcpython-6c6b3f770d0b54eeb3e42b38e1fe5d893c38dd6e.zip
cpython-6c6b3f770d0b54eeb3e42b38e1fe5d893c38dd6e.tar.gz
cpython-6c6b3f770d0b54eeb3e42b38e1fe5d893c38dd6e.tar.bz2
Issue #19352: Fix unittest discovery when a module can be reached through several paths (e.g. under Debian/Ubuntu with virtualenv).
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_discovery.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/unittest/test/test_discovery.py b/Lib/unittest/test/test_discovery.py
index 11ec9ed..d4eff40 100644
--- a/Lib/unittest/test/test_discovery.py
+++ b/Lib/unittest/test/test_discovery.py
@@ -366,7 +366,7 @@ class TestDiscovery(unittest.TestCase):
self.assertTrue(program.failfast)
self.assertTrue(program.catchbreak)
- def test_detect_module_clash(self):
+ def setup_module_clash(self):
class Module(object):
__file__ = 'bar/foo.py'
sys.modules['foo'] = Module
@@ -393,7 +393,10 @@ class TestDiscovery(unittest.TestCase):
os.listdir = listdir
os.path.isfile = isfile
os.path.isdir = isdir
+ return full_path
+ def test_detect_module_clash(self):
+ full_path = self.setup_module_clash()
loader = unittest.TestLoader()
mod_dir = os.path.abspath('bar')
@@ -406,6 +409,25 @@ class TestDiscovery(unittest.TestCase):
)
self.assertEqual(sys.path[0], full_path)
+ def test_module_symlink_ok(self):
+ full_path = self.setup_module_clash()
+
+ original_realpath = os.path.realpath
+
+ mod_dir = os.path.abspath('bar')
+ expected_dir = os.path.abspath('foo')
+
+ def cleanup():
+ os.path.realpath = original_realpath
+ self.addCleanup(cleanup)
+
+ def realpath(path):
+ if path == os.path.join(mod_dir, 'foo.py'):
+ return os.path.join(expected_dir, 'foo.py')
+ return path
+ os.path.realpath = realpath
+ loader = unittest.TestLoader()
+ loader.discover(start_dir='foo', pattern='foo.py')
def test_discovery_from_dotted_path(self):
loader = unittest.TestLoader()