0

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?

h4ck3rm1k3
  • 2,060
  • 22
  • 33
John Wang
  • 4,562
  • 9
  • 37
  • 54

2 Answers2

0

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

fredley
  • 32,953
  • 42
  • 145
  • 236
0

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
  • 2,365
  • 17
  • 16