This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author msyang
Recipients msyang
Date 2009-01-08.21:21:24
SpamBayes Score 0.0044517545
Marked as misclassified No
Message-id <1231449686.43.0.781017317614.issue4886@psf.upfronthosting.co.za>
In-reply-to
Content
I want to use the included test.regrtest (located in 
$pythondir/lib/python[ver]/test) to regression test some of my own 
scripts located in directory myDir.  The script has some nice 
configurability features to skip some tests based on machine 
configurations, etc. that a vanilla unittest suite doesn't include 
automatically.  However, it seems that the script regrtest.py has an 
error following the __import__ line.

Here's my setup:

/sample.py
/myDir
    /__init__.py
    /test_file1.py
    /test_file2.py
    /...

in sample.py:

{{{
#!python
#!/usr/bin/env python
import test.regrtest as rt
rt.main(tests = ['myDir.test_file1','myDir.test_file2'], \
quiet = False, verbose = True)
}}}

running sample.py yields:

{{{
#!sh
myDir.test_file1
myDir.test_file1 skipped -- No module named myDir.test_file1
myDir.test_file2
myDir.test_file2 skipped -- No module named myDir.test_file2
2 tests skipped:
    myDir.test_file1 myDir.test_file2
2 skips unexpected on win32:
    myDir.test_file1 myDir.test_file2
}}}

This is due to the code snippet in regrtest.py around line 554:

{{{
#!python
...
            if test.startswith('test.'):
                abstest = test
            else:
                # Always import it from the test package
                abstest = 'test.' + test
            the_package = __import__(abstest, globals(), locals(), [])
            the_module = getattr(the_package, test)
...
}}}

should be changed to:
{{{
#!python
...
            if test.startswith('test.'):
                abstest = test
                modName = test[len('test.'):]
            else:
                # Always import it from the test package
                abstest = 'test.' + test
                modName = test
            the_package = __import__(abstest, globals(), locals(), [])
            the_module = getattr(the_package, modName)
...
}}}

This way, the the_module will correctly find the module name in 
'the_package'.

A further recommendation: the main() module should be able to work with 
test directories with name other than 'test.*'.  Otherwise, users 
wishing to use the main() on other directories will have to name them 
'test.'  Depending on the user's directory's position in sys.path 
(before or after $pythondir/lib/python[ver]), regrtest.main() will 
either fail due to the 'from test import ...' statements being shadowed 
by the user's 'test' directory or the user's 'test' directory being 
shadowed by the standard library's.
History
Date User Action Args
2009-01-08 21:21:26msyangsetrecipients: + msyang
2009-01-08 21:21:26msyangsetmessageid: <1231449686.43.0.781017317614.issue4886@psf.upfronthosting.co.za>
2009-01-08 21:21:25msyanglinkissue4886 messages
2009-01-08 21:21:24msyangcreate