Testing
qtile-expanded includes a comprehensive test suite that can be run with pytest.
Running Tests
To run all tests:
pytest -v --no-xephyr
Test Options
# Run with verbose output
pytest -v --no-xephyr
# Run specific test file
pytest tests/test_storage.py -v --no-xephyr
# Run specific test
pytest tests/test_storage.py::TestStateStorage::test_persistence -v
# Run with coverage
pytest --cov=qtile_expanded --cov-report=html --no-xephyr
# Show test collection without running
pytest --collect-only
Xephyr Tests
For tests that require a running X server (Xephyr), use:
pytest --backend x11
This will automatically launch Xephyr instances for testing. Xephyr must be installed on your system.
Installing Xephyr
On Debian/Ubuntu:
sudo apt-get install xvfb xephyr
On Fedora/RHEL:
sudo dnf install xorg-x11-server-Xephyr xorg-x11-utils
Test Structure
The test suite is organized as follows:
tests/
├── __init__.py # Test package init
├── conftest.py # Pytest fixtures and configuration
├── test_storage.py # Tests for StateStorage (14 tests)
└── test_notification_bell.py # Tests for NotificationBell (16 tests)
Test Fixtures
The following fixtures are available in tests:
- temp_cache_dir
Creates a temporary cache directory for testing StateStorage
- mock_qtile
Creates a mock Qtile object with screen information
- notification_data
Provides sample notification data for testing
Writing Tests
When writing new tests:
Place test files in the
tests/directoryUse the
--no-xephyrflag for tests that don’t need XUse the
@pytest.mark.xephyrdecorator for tests that require XUse fixtures from
conftest.pywhen possibleKeep tests focused and independent
Example Test
import pytest
def test_something(temp_cache_dir, monkeypatch):
monkeypatch.setenv("HOME", str(temp_cache_dir.parent))
from qtile_expanded import StateStorage
storage = StateStorage("test")
storage.set("key", "value")
assert storage.get("key") == "value"
Test Dependencies
To install test dependencies:
pip install pytest pytest-cov
Continuous Integration
The test suite is designed to work with CI systems. For local development, run:
# Run all tests
pytest --no-xephyr
# Run with coverage and generate report
pytest --cov=qtile_expanded --cov-report=html --no-xephyr
# Open coverage report in browser
xdg-open htmlcov/index.html