wabot/tests/integration/conftest.py

44 lines
1.2 KiB
Python

"""Shared fixtures for real-browser integration tests.
Every test in this directory is marked ``integration`` automatically and
runs with NoPacing (human delays would make the suite glacial). Browsers
run headless against static HTML served from tests/fixtures.
"""
import functools
import http.server
import threading
from pathlib import Path
import pytest
FIXTURES = Path(__file__).parent.parent / "fixtures"
BROWSERS = ["firefox", "chromium"]
def pytest_collection_modifyitems(items):
integration_dir = Path(__file__).parent
for item in items:
if integration_dir in item.path.parents:
item.add_marker(pytest.mark.integration)
@pytest.fixture(scope="session")
def site_url():
"""Serve tests/fixtures over HTTP on an ephemeral port."""
handler = functools.partial(
http.server.SimpleHTTPRequestHandler, directory=str(FIXTURES)
)
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
yield f"http://127.0.0.1:{server.server_address[1]}"
server.shutdown()
@pytest.fixture
def store(tmp_path):
from wabot.sessions import SessionStore
return SessionStore(path=tmp_path / "sessions.json")