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.

classification
Title: test/regrtest.py contains error on __import__
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: msyang, r.david.murray
Priority: normal Keywords:

Created on 2009-01-08 21:21 by msyang, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg79442 - (view) Author: Michael Yang (msyang) Date: 2009-01-08 21:21
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.
msg84955 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-04-01 01:39
regrtest is an internal tool for testing python, and is not suited to be
used as a general testing framework.  You would be far better off using
one of the 3rd party packages designed for that task.  We don't have the
resources to support use of regrtest for anything except testing of
python itself.
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49136
2009-04-01 01:39:35r.david.murraysetstatus: open -> closed

type: behavior -> enhancement

nosy: + r.david.murray
messages: + msg84955
resolution: rejected
stage: resolved
2009-01-08 21:21:45msyangsettype: behavior
2009-01-08 21:21:25msyangcreate