mirror of
https://github.com/HelloZeroNet/ZeroNet.git
synced 2023-12-14 04:33:03 +01:00
Better cleanup after tests
This commit is contained in:
parent
74e71a1971
commit
b6286372fb
1 changed files with 14 additions and 5 deletions
|
@ -7,6 +7,7 @@ import json
|
|||
import shutil
|
||||
import gc
|
||||
import datetime
|
||||
import atexit
|
||||
|
||||
import pytest
|
||||
import mock
|
||||
|
@ -74,11 +75,6 @@ from Plugin import PluginManager
|
|||
config.data_dir = "src/Test/testdata" # Use test data for unittests
|
||||
|
||||
os.chdir(os.path.abspath(os.path.dirname(__file__) + "/../..")) # Set working dir
|
||||
# Cleanup content.db caches
|
||||
if os.path.isfile("%s/content.db" % config.data_dir):
|
||||
os.unlink("%s/content.db" % config.data_dir)
|
||||
if os.path.isfile("%s-temp/content.db" % config.data_dir):
|
||||
os.unlink("%s-temp/content.db" % config.data_dir)
|
||||
|
||||
PluginManager.plugin_manager.loadPlugins()
|
||||
config.loadPlugins()
|
||||
|
@ -106,6 +102,19 @@ from util import RateLimit
|
|||
from Db import Db
|
||||
|
||||
|
||||
def cleanup():
|
||||
sys.modules["Db.Db"].dbCloseAll()
|
||||
for dir_path in [config.data_dir, config.data_dir + "-temp"]:
|
||||
for file_name in os.listdir(dir_path):
|
||||
ext = file_name.rsplit(".", 1)[-1]
|
||||
if ext not in ["csr", "pem", "srl", "db", "json"]:
|
||||
continue
|
||||
file_path = dir_path + "/" + file_name
|
||||
if os.path.isfile(file_path):
|
||||
os.unlink(file_path)
|
||||
|
||||
atexit.register(cleanup)
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def resetSettings(request):
|
||||
open("%s/sites.json" % config.data_dir, "w").write("{}")
|
||||
|
|
Loading…
Reference in a new issue