-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
59 lines (49 loc) · 1.94 KB
/
conftest.py
File metadata and controls
59 lines (49 loc) · 1.94 KB
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
51
52
53
54
55
56
57
58
"""
Pytest configuration and fixtures for Sentience SDK tests
"""
import os
import pytest
from pathlib import Path
def pytest_configure(config):
"""Register custom markers"""
config.addinivalue_line(
"markers", "requires_extension: mark test as requiring the sentience-chrome extension"
)
@pytest.fixture(scope="session")
def extension_available():
"""Check if the sentience-chrome extension is available"""
# Check if extension exists
# __file__ is sdk-python/tests/conftest.py
# parent = sdk-python/tests/
# parent.parent = sdk-python/
# parent.parent.parent = Sentience/ (project root)
repo_root = Path(__file__).parent.parent.parent
extension_source = repo_root / "sentience-chrome"
# Also check for required extension files
if extension_source.exists():
required_files = ["manifest.json", "content.js", "injected_api.js"]
pkg_dir = extension_source / "pkg"
if pkg_dir.exists():
# Check if WASM files exist
wasm_files = ["sentience_core.js", "sentience_core_bg.wasm"]
all_exist = all(
(extension_source / f).exists() for f in required_files
) and all(
(pkg_dir / f).exists() for f in wasm_files
)
return all_exist
return False
@pytest.fixture(autouse=True)
def skip_if_no_extension(request, extension_available):
"""Automatically skip tests that require extension if it's not available"""
# Check if test is marked as requiring extension
marker = request.node.get_closest_marker("requires_extension")
if marker and not extension_available:
# In CI, skip silently
# Otherwise, show a helpful message
if os.getenv("CI"):
pytest.skip("Extension not available in CI environment")
else:
pytest.skip(
"Extension not found. Build it first: cd ../sentience-chrome && ./build.sh"
)