Testing Guide#
The testing infrastructure uses pytest and beautifulsoup4 to validate
generated HTML. Always run tests via tox for proper environment isolation.
Running Tests#
# Full test suite (Python 3.12 + 3.13, Sphinx 7)
$ tox
# Specific test file
$ tox -- tests/test_module_structure.py -v
# Tests matching a pattern
$ tox -- -k "test_scss"
Test Structure#
tests/
├── conftest.py # Shared pytest fixtures
├── test_build.py # HTML build and regression tests
├── test_module_structure.py # Module organization tests
├── test_custom_colors.py # Color scheme tests
├── test_rtl_functionality.py # RTL language support tests
└── sites/ # Test site configurations
├── base/ # Basic test site
└── rtl_test/ # RTL-specific test site
Fixtures#
Defined in conftest.py:
Fixture |
Path |
Purpose |
|---|---|---|
|
Repository root |
Access to top-level files |
|
|
Python source directory |
|
|
Source assets (SCSS/JS) |
|
|
Sphinx theme templates |
|
|
SCSS source files |
|
|
JavaScript source files |
Example#
def test_my_feature(styles_dir):
"""Example test using the styles_dir fixture."""
index_scss = styles_dir / "index.scss"
assert index_scss.exists()
content = index_scss.read_text()
assert "@forward" in content
Module Structure Tests#
test_module_structure.py validates the modular organization of SCSS and JS.
SCSS tests#
test_all_scss_modules_exist— verifies all 23 expected SCSS files existtest_index_scss_imports_modules— verifies@forwarddirectives for all 11 component modulestest_scss_modules_use_sass_module_syntax— verifies modules use@usenot@import
JavaScript tests#
test_all_js_modules_exist— verifies all 9 expected JS files existtest_index_js_imports_all_modules— verifies all 8 feature modules are importedtest_js_modules_export_functions— verifies each module exports expected functionstest_no_console_polyfill— verifies obsolete IE8/9 polyfill is removed
Layout template tests#
test_preconnect_hints_present— verifies<link rel="preconnect">hints for CDN domainstest_sri_hashes_present— verifies SRI integrity attributes on CDN scriptstest_external_scripts_loaded— verifies Popper.js, Tippy.js, and Feather Icons are loaded
Build Tests#
test_build.py builds actual Sphinx sites and validates the generated HTML.
Regression testing#
We use pytest-regressions to detect changes in HTML output:
def test_build_book(file_regression):
html = build_and_get_html()
file_regression.check(html, extension=".html")
To update regression files after intentional changes:
$ tox -- --force-regen
Writing New Tests#
Guidelines#
Use fixtures — avoid hardcoding paths
Test one thing — each test verifies a single behavior
Descriptive names —
test_feature_behavior_expected_resultInclude docstrings — explain what and why
Example#
class TestNewFeature:
"""Tests for the new feature."""
def test_feature_file_exists(self, scripts_dir):
"""Verify the new feature module exists."""
module_path = scripts_dir / "new-feature.js"
assert module_path.exists(), "Missing new-feature.js module"
def test_feature_exports_init_function(self, scripts_dir):
"""Verify the module exports its init function."""
content = (scripts_dir / "new-feature.js").read_text()
assert "export function initNewFeature" in content
Continuous Integration#
Tests run on GitHub Actions for every push and pull request:
Pre-commit checks (black, flake8)
Full test suite with
toxDocumentation build
Visual regression tests (see Visual Testing)