Edgewall Software
Modify

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#9682 closed defect (fixed)

Test suite fails on Python 2.7

Reported by: Remy Blank Owned by: Remy Blank
Priority: normal Milestone: 0.12.2
Component: general Version: 0.12-stable
Severity: normal Keywords: python27
Cc: Branch:
Release Notes:

Fixed test suite failure on Python 2.7.

API Changes:
Internal Changes:

Description

The test suite has been reported by the Gentoo Linux project to fail on Python 2.7:

Traceback (most recent call last):
  File "trac/test.py", line 441, in <module>
    unittest.main(defaultTest='suite')
  File "/usr/lib64/python2.7/unittest/main.py", line 95, in __init__
    self.runTests()
  File "/usr/lib64/python2.7/unittest/main.py", line 229, in runTests
    self.result = testRunner.run(self.test)
  File "/usr/lib64/python2.7/unittest/runner.py", line 151, in run
    test(result)
  File "/usr/lib64/python2.7/unittest/suite.py", line 65, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib64/python2.7/unittest/suite.py", line 85, in run
    self._wrapped_run(result)
  File "/usr/lib64/python2.7/unittest/suite.py", line 115, in _wrapped_run
    test._wrapped_run(result, debug)
  File "/usr/lib64/python2.7/unittest/suite.py", line 115, in _wrapped_run
    test._wrapped_run(result, debug)
  File "/usr/lib64/python2.7/unittest/suite.py", line 115, in _wrapped_run
    test._wrapped_run(result, debug)
  File "/usr/lib64/python2.7/unittest/suite.py", line 115, in _wrapped_run
    test._wrapped_run(result, debug)
TypeError: _wrapped_run() takes exactly 2 arguments (3 given)

Attachments (0)

Change History (13)

comment:1 by Remy Blank, 14 years ago

The following patch fixes the issue for me:

  • trac/test.py

    diff --git a/trac/test.py b/trac/test.py
    a b class TestSetup(unittest.TestSuite):  
    139139        self.tearDown()
    140140        return result
    141141
    142     def _wrapped_run(self, result):
     142    def _wrapped_run(self, *args, **kwargs):
    143143        "Python 2.7 / unittest2 compatibility - there must be a better way..."
    144144        self.setUp()
    145145        if hasattr(self, 'fixture'):
    146146            for test in self._tests:
    147147                if hasattr(test, 'setFixture'):
    148148                    test.setFixture(self.fixture)
    149         unittest.TestSuite._wrapped_run(self, result)
     149        unittest.TestSuite._wrapped_run(self, *args, **kwargs)
    150150        self.tearDown()
    151         return result
    152151
    153152class TestCaseSetup(unittest.TestCase):
    154153    def setFixture(self, fixture):
Last edited 14 years ago by Remy Blank (previous) (diff)

comment:2 by Christian Boos, 14 years ago

Fix confirmed on my side, test suite pass (only in-memory SQLite tested so far, "bigtest" in progress). I suppose that correspond to a last minute change on their side between rc2 and final (I had rc2 installed until this week-end, and I'm pretty sure I tested 0.12 with that one).

So this is just a unittest induced glitch, no need to modify anything in the release notes, Trac 0.12.1, as did 0.12 before, works perfectly well with Python 2.7.

comment:3 by Christian Boos, 14 years ago

Scratch that… I specified python=27 but 2.6.5 was used due to a misconfiguration.

comment:4 by Remy Blank, 14 years ago

Thanks for testing. I noticed another (unrelated) issue with Python 2.7 on Windows 7. Every second run of the test suite fails on creation of the testenv folder. After the failure, the folder disappears, so the next run passes.

Looking at the code, the corresponding line looks very suspect, as os.mkdir() isn't supposed to return anything. I haven't had time to investigate further.

in reply to:  3 ; comment:5 by Christian Boos, 14 years ago

Ok, there's apparently a different problem when running the tests using the following command line:

$ python ./trac/test.py --skip-functional-tests
Traceback (most recent call last):
  File "./trac/test.py", line 427, in <module>
    unittest.main(defaultTest='suite')
  File "C:\Dev\Python27\lib\unittest\main.py", line 94, in __init__
    self.parseArgs(argv)
  File "C:\Dev\Python27\lib\unittest\main.py", line 149, in parseArgs
    self.createTests()
  File "C:\Dev\Python27\lib\unittest\main.py", line 158, in createTests
    self.module)
  File "C:\Dev\Python27\lib\unittest\loader.py", line 128, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "C:\Dev\Python27\lib\unittest\loader.py", line 113, in loadTestsFromName
    test = obj()
  File "./trac/test.py", line 392, in suite
    import trac.tests
ImportError: No module named tests

No idea why, yet.

But it works fine using python -m trac.test or even python setup.py test. This way, all unit tests pass, and the functional tests need the patch from comment:1.

Tested on Windows 7 (x64) with Python 2.7 (x86):

  • OK for sqlite::memory: with the builtin sqlite
  • OK for mysql: with MySQLdb 1.2.3
  • OK for postgresql: with psycopg2-2.2.2 (well, I actually have 11 failures, but they are all due to the switch to 9.0.1, no real failure; fixes for the failing tests will come separately)
  • FAIL for sqlite:test27.db (builtin sqlite)
    Initenv for 'C:\Workspace\src\trac\repos\trunk\testenv\trac' failed.
    Failed to create environment.
    [Error 183] Cannot create a file when that file already exists: u'C:\\Workspace\\src\\trac\\repos\\trunk\\testenv\\trac'
    
    Perhaps this is related to the issue you mentioned in comment:4? But it happens systematically for me (and 2.6.5 works fine for this new backend)

I didn't test the following:

SKIP: versioncontrol/tests/functional.py (no svn bindings)
SKIP: versioncontrol/tests/svn_fs.py (no svn bindings)
SKIP: tracopt/mimeview/tests/php.py (php cli binary, 'php', not found)

Python 2.7 bindings for Subversion, anyone?

Last edited 14 years ago by Christian Boos (previous) (diff)

comment:6 by Remy Blank, 14 years ago

Patch from comment:1 applied in [10219].

comment:7 by Remy Blank, 14 years ago

Here's the traceback for the issue I mentioned in comment:4:

Traceback (most recent call last):
  File "trac\test.py", line 441, in <module>
    unittest.main(defaultTest='suite')
  File "C:\Python27\Lib\unittest\main.py", line 95, in __init__
    self.runTests()
  File "C:\Python27\Lib\unittest\main.py", line 229, in runTests
    self.result = testRunner.run(self.test)
  File "C:\Python27\Lib\unittest\runner.py", line 151, in run
    test(result)
  File "C:\Python27\Lib\unittest\suite.py", line 65, in __call__
    return self.run(*args, **kwds)
  File "C:\Python27\Lib\unittest\suite.py", line 85, in run
    self._wrapped_run(result)
  File "C:\Python27\Lib\unittest\suite.py", line 115, in _wrapped_run
    test._wrapped_run(result, debug)
  File "C:\Python27\Lib\unittest\suite.py", line 115, in _wrapped_run
    test._wrapped_run(result, debug)
  File "Z:\src\trac\0.12-stable-2.7\trac\test.py", line 144, in _wrapped_run
    self.setUp()
  File "Z:\src\trac\0.12-stable-2.7\trac\tests\functional\__init__.py", line 121, in setUp
    self._testenv = self.env_class(dirname, port, baseurl)
  File "Z:\src\trac\0.12-stable-2.7\trac\tests\functional\testenv.py", line 58, in __init__
    self.create()
  File "Z:\src\trac\0.12-stable-2.7\trac\tests\functional\testenv.py", line 114, in create
    if os.mkdir(self.dirname):
WindowsError: [Error 5] Access is denied: 'Z:\\src\\trac\\0.12-stable-2.7\\testenv'

It seems this has nothing to do with Python 2.7, and everything with Windows (or VirtualBox). The "access denied" error comes from the testenv directory not being removed completely when the os.rmdir() call returns (possibly due to Windows Explorer), and the subsequent os.mkdir() being denied creation.

Start the following program on Windows 7 from the command-line, with no Windows Explorer windows open:

import os

path = 'testenv'

while True:
    try:
        os.rmdir(path)
    except OSError:
        pass
    os.mkdir(path)

Nothing happens, the directory is created and destroyed repeatedly. Now, open a Windows Explorer window and navigate to the directory where you launched the script, and expand that folder in the tree view on the left. Here (Windows 7 VM on VirtualBox), the script traps within a few seconds. The symptom is the same with both Python 2.6 and 2.7.

Adding even a very small pause (1 ms) before the os.mkdir() fixes the issue. So I suggest the following patch:

  • trac/tests/functional/testenv.py

    diff --git a/trac/tests/functional/testenv.py b/trac/tests/functional/testenv.py
    a b class FunctionalTestEnvironment(object):  
    5555        self.pid = None
    5656        self.init()
    5757        self.destroy()
     58        time.sleep(0.1) # Avoid race condition on Windows
    5859        self.create()
    5960        locale.setlocale(locale.LC_ALL, '')
    6061

in reply to:  5 comment:8 by Christian Boos, 14 years ago

  • OK for postgresql: with psycopg2-2.2.2 (well, I actually have 11 failures, but they are all due to the switch to 9.0.1, no real failure; fixes for the failing tests will come separately)

In r10221 and r10223.

in reply to:  7 ; comment:9 by Christian Boos, 14 years ago

Replying to rblank:

Here's the traceback for the issue I mentioned in comment:4:

I didn't observe that error, but:

The "access denied" error comes from the testenv directory not being removed completely when the os.rmdir() call returns (possibly due to Windows Explorer), and the subsequent os.mkdir() being denied creation.

I can see that as well with plain Windows 7, with the test script.

Adding even a very small pause (1 ms) before the os.mkdir() fixes the issue.

Should work fine, please commit.

Unfortunately, the error I mentioned in comment:5 for the sqlite: backend is still there, so it must be a different issue.

comment:10 by Remy Blank, 14 years ago

Patch from comment:7 applied in [10225].

in reply to:  9 comment:11 by Christian Boos, 14 years ago

Replying to cboos:

Unfortunately, the error I mentioned in comment:5 for the sqlite: backend is still there, so it must be a different issue.

Problem solved, I had an easy_install of 0.12.1 interfering.

Onto the make test issue… argh, was the same problem ;-)
All green on my side, now.

in reply to:  5 comment:12 by Remy Blank, 14 years ago

Resolution: fixed
Status: newclosed

Replying to cboos:

  • FAIL for sqlite:test27.db (builtin sqlite)
    Initenv for 'C:\Workspace\src\trac\repos\trunk\testenv\trac' failed.
    Failed to create environment.
    [Error 183] Cannot create a file when that file already exists: u'C:\\Workspace\\src\\trac\\repos\\trunk\\testenv\\trac'
    

That one was due to the SQLite connector trying to os.makedirs() an existing directory. Running with sqlite:db\test27.db works great. I have fixed the issue in [10231], and removed the suspect code from comment:4 in [10232].

comment:13 by Remy Blank, 14 years ago

Release Notes: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.