views:

41

answers:

2

Hi,

I'm using nose test framework. When running a test module, the teardown function defined in it failed. the error raised says the fixture is locked by another process. here is my test module, test_my_module.py:

... ...    
def teardown():
    if os.path.exists(test_output_dir):
        shutil.rmtree(test_output_dir)
... ...

@with_setup(init_test_db, destroy_test_db)
def test_foo1():
    eq_(foo1(),1)

@with_setup(init_test_db, destroy_test_db)
def test_foo2():
    eq_(foo2(),2)
... ...

There is a db(sqlite3) file in the test_output_dir which been used as fixture. Actually it is that db file that cannot be remove by the teardown, due to it be locked by other process. To my understand, a teardown will always run after all test functions finished running. So why does that happen ? why can those test functions still lock the db file? Is it a sqlite3 issue or it's some wrong in my test code?

A: 

You could try explicitly closing the sqlite connection in the teardown before removing test_output_dir.

fredley
it doesnt work even explicitly closing the sqlite connection.
john wang
A: 

I believe I did have the same issue in my c# unit tests.

I solved it by using calling SqliteConnection.ClearAllPools() before deleting the database file, so it is related to connection pooling.

Maybe there is an equivalent method in python? I really don't know.

TTT