1- import os
1+ import os .path
2+ from os .path import abspath
23import re
34import sys
45import types
@@ -250,7 +251,7 @@ def restore_isfile():
250251 def restore_isdir ():
251252 os .path .isdir = original_isdir
252253 self .addCleanup (restore_isdir )
253- self .addCleanup (sys .path .remove , '/foo' )
254+ self .addCleanup (sys .path .remove , abspath ( '/foo' ) )
254255
255256 # Test data: we expect the following:
256257 # a listdir to find our package, and a isfile and isdir check on it.
@@ -263,8 +264,8 @@ def restore_isdir():
263264 # the module load tests for both package and plain module called,
264265 # and the plain module result nested by the package module load_tests
265266 # indicating that it was processed and could have been mutated.
266- vfs = {'/foo' : ['my_package' ],
267- '/foo/my_package' : ['__init__.py' , 'test_module.py' ]}
267+ vfs = {abspath ( '/foo' ) : ['my_package' ],
268+ abspath ( '/foo/my_package' ) : ['__init__.py' , 'test_module.py' ]}
268269 def list_dir (path ):
269270 return list (vfs [path ])
270271 os .listdir = list_dir
@@ -301,10 +302,10 @@ def __eq__(self, other):
301302 loader ._get_module_from_name = lambda name : Module (name )
302303 loader .suiteClass = lambda thing : thing
303304
304- loader ._top_level_dir = '/foo'
305+ loader ._top_level_dir = abspath ( '/foo' )
305306 # this time no '.py' on the pattern so that it can match
306307 # a test package
307- suite = list (loader ._find_tests ('/foo' , 'test*.py' ))
308+ suite = list (loader ._find_tests (abspath ( '/foo' ) , 'test*.py' ))
308309
309310 # We should have loaded tests from both my_package and
310311 # my_pacakge.test_module, and also run the load_tests hook in both.
@@ -404,18 +405,18 @@ def test_discover_with_modules_that_fail_to_import(self):
404405 test .test_this_does_not_exist ()
405406
406407 def test_discover_with_init_modules_that_fail_to_import (self ):
407- vfs = {'/foo' : ['my_package' ],
408- '/foo/my_package' : ['__init__.py' , 'test_module.py' ]}
408+ vfs = {abspath ( '/foo' ) : ['my_package' ],
409+ abspath ( '/foo/my_package' ) : ['__init__.py' , 'test_module.py' ]}
409410 self .setup_import_issue_package_tests (vfs )
410411 import_calls = []
411412 def _get_module_from_name (name ):
412413 import_calls .append (name )
413414 raise ImportError ("Cannot import Name" )
414415 loader = unittest .TestLoader ()
415416 loader ._get_module_from_name = _get_module_from_name
416- suite = loader .discover ('/foo' )
417+ suite = loader .discover (abspath ( '/foo' ) )
417418
418- self .assertIn ('/foo' , sys .path )
419+ self .assertIn (abspath ( '/foo' ) , sys .path )
419420 self .assertEqual (suite .countTestCases (), 1 )
420421 test = list (list (suite )[0 ])[0 ] # extract test from suite
421422 with self .assertRaises (ImportError ):
@@ -439,18 +440,18 @@ def _get_module_from_name(name):
439440 self .assertEqual (len (result .skipped ), 1 )
440441
441442 def test_discover_with_init_module_that_raises_SkipTest_on_import (self ):
442- vfs = {'/foo' : ['my_package' ],
443- '/foo/my_package' : ['__init__.py' , 'test_module.py' ]}
443+ vfs = {abspath ( '/foo' ) : ['my_package' ],
444+ abspath ( '/foo/my_package' ) : ['__init__.py' , 'test_module.py' ]}
444445 self .setup_import_issue_package_tests (vfs )
445446 import_calls = []
446447 def _get_module_from_name (name ):
447448 import_calls .append (name )
448449 raise unittest .SkipTest ('skipperoo' )
449450 loader = unittest .TestLoader ()
450451 loader ._get_module_from_name = _get_module_from_name
451- suite = loader .discover ('/foo' )
452+ suite = loader .discover (abspath ( '/foo' ) )
452453
453- self .assertIn ('/foo' , sys .path )
454+ self .assertIn (abspath ( '/foo' ) , sys .path )
454455 self .assertEqual (suite .countTestCases (), 1 )
455456 result = unittest .TestResult ()
456457 suite .run (result )
0 commit comments