开发者

why python nose unittest teardown fixture failed

开发者 https://www.devze.com 2023-01-19 12:50 出处:网络
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_

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 function开发者_StackOverflows still lock the db file? Is it a sqlite3 issue or it's some wrong in my test code?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消