mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-13 19:45:56 +00:00
Finalse pytest methods
This commit is contained in:
@@ -10,33 +10,39 @@ from backend import store
|
||||
# Much better boilerplate than the docs
|
||||
# https://www.python-boilerplate.com/py3+flask+pytest/
|
||||
|
||||
global app
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def app(request):
|
||||
"""Create application for the tests."""
|
||||
|
||||
datastore_path = "./test-datastore"
|
||||
|
||||
import os
|
||||
try:
|
||||
os.unlink("{}/url-watches.json".format(datastore_path))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
app_config = {'datastore_path': datastore_path}
|
||||
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'])
|
||||
_app = changedetection_app(app_config, datastore)
|
||||
app = changedetection_app(app_config, datastore)
|
||||
|
||||
# Establish an application context before running the tests.
|
||||
ctx = _app.app_context()
|
||||
ctx.push()
|
||||
#ctx = _app.app_context()
|
||||
#ctx.push()
|
||||
|
||||
def teardown():
|
||||
ctx.pop()
|
||||
datastore.stop_thread = True
|
||||
app.config['STOP_THREADS']= True
|
||||
|
||||
request.addfinalizer(teardown)
|
||||
return _app
|
||||
return app
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def client(app):
|
||||
with app.test_client() as client:
|
||||
yield client
|
||||
#@pytest.fixture(scope='session')
|
||||
#def client(app):
|
||||
# with app.test_client() as client:
|
||||
# yield client
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def session(request):
|
||||
"""Creates a new database session for a test."""
|
||||
return session
|
||||
|
||||
Reference in New Issue
Block a user