otree-server / tests /test_e2e_bots.py
BPEL Bot
Initial Hugging Face deployment
e40dce0
import os
import subprocess
from pathlib import Path
import time
PROJECT_DIR = Path(__file__).resolve().parents[1]
OTREE = PROJECT_DIR.parents[1] / 'venv' / 'bin' / 'otree'
def run_otree_test(app: str):
env = os.environ.copy()
# Ensure a fresh SQLite DB per test run to avoid schema/version conflicts
db_name = f"test_db_{app}_{int(time.time()*1000)}.sqlite3"
env['OTREE_DATABASE_URL'] = f"sqlite:///{db_name}"
# Also remove default db.sqlite3 if present
default_db = PROJECT_DIR / 'db.sqlite3'
if default_db.exists():
default_db.unlink()
proc = subprocess.run(
[str(OTREE), 'test', app],
cwd=str(PROJECT_DIR),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
env=env,
)
if proc.returncode != 0:
print(proc.stdout)
assert proc.returncode == 0, f"oTree bot tests failed for {app}"
def test_bots_policy_nudges_sequence():
run_otree_test('policy_nudges')
def test_bots_guessing_game_demo_sequence():
run_otree_test('guessing_game_demo')
def test_bots_survey_biases_sequence():
run_otree_test('survey_biases_full')
def test_bots_classic_baseline_sequence():
# Reproduce navigation/rendering issues in the classic baseline sequence
# (e.g., template expressions not supported by oTree's template engine).
run_otree_test('classic_baseline')