-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathconftest.py
More file actions
51 lines (40 loc) · 1.37 KB
/
conftest.py
File metadata and controls
51 lines (40 loc) · 1.37 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
"""Pytest configuration and fixtures for webapp-manager tests."""
import os
import sys
from contextlib import contextmanager
import pytest
# Add webapp-manager library to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "usr", "lib", "webapp-manager"))
@contextmanager
def mock_environment(**env_vars):
"""Context manager to temporarily set environment variables."""
original = {}
for key, value in env_vars.items():
original[key] = os.environ.get(key)
if value is None:
os.environ.pop(key, None)
else:
os.environ[key] = value
try:
yield
finally:
for key, orig_value in original.items():
if orig_value is None:
os.environ.pop(key, None)
else:
os.environ[key] = orig_value
@pytest.fixture
def wayland_env():
"""Fixture to simulate a Wayland session environment."""
with mock_environment(XDG_SESSION_TYPE="wayland", WAYLAND_DISPLAY="wayland-0"):
yield
@pytest.fixture
def x11_env():
"""Fixture to simulate an X11 session environment."""
with mock_environment(XDG_SESSION_TYPE="x11", WAYLAND_DISPLAY=None):
yield
@pytest.fixture
def unset_env():
"""Fixture with display environment variables unset."""
with mock_environment(XDG_SESSION_TYPE=None, WAYLAND_DISPLAY=None):
yield