forked from jupyter-server/jupyter-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
50 lines (38 loc) · 1.37 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from pathlib import Path
import pytest
from jupyter_scheduler.orm import create_session, create_tables
from jupyter_scheduler.scheduler import Scheduler
from jupyter_scheduler.tests.mocks import MockEnvironmentManager
pytest_plugins = ("jupyter_server.pytest_plugin",)
HERE = Path(__file__).parent.resolve()
DB_FILE_PATH = f"{HERE}/jupyter_scheduler/tests/testdb.sqlite"
DB_URL = f"sqlite:///{DB_FILE_PATH}"
@pytest.fixture
def jp_server_config(jp_server_config):
return {
"ServerApp": {"jpserver_extensions": {"jupyter_scheduler": True}},
"SchedulerApp": {
"db_url": DB_URL,
"drop_tables": True,
"environment_manager_class": "jupyter_scheduler.tests.mocks.MockEnvironmentManager",
},
"BaseScheduler": {
"execution_manager_class": "jupyter_scheduler.tests.mocks.MockExecutionManager"
},
"Scheduler": {"task_runner_class": "jupyter_scheduler.tests.mocks.MockTaskRunner"},
}
@pytest.fixture(autouse=True)
def setup_db():
create_tables(DB_URL, True)
yield
if os.path.exists(DB_FILE_PATH):
os.remove(DB_FILE_PATH)
@pytest.fixture
def jp_scheduler_db():
return create_session(DB_URL)
@pytest.fixture
def jp_scheduler(jp_data_dir):
return Scheduler(
db_url=DB_URL, root_dir=str(jp_data_dir), environments_manager=MockEnvironmentManager()
)