Use subtests in tests/test_docs.py (#2609)

Closes #2608
This commit is contained in:
Simon Willison 2025-12-04 21:36:39 -08:00 committed by GitHub
commit 1d4448fc56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 25 deletions

View file

@ -69,7 +69,7 @@ docs = [
"ruamel.yaml", "ruamel.yaml",
] ]
test = [ test = [
"pytest>=5.2.2", "pytest>=9",
"pytest-xdist>=2.2.1", "pytest-xdist>=2.2.1",
"pytest-asyncio>=1.2.0", "pytest-asyncio>=1.2.0",
"beautifulsoup4>=4.8.1", "beautifulsoup4>=4.8.1",

View file

@ -28,8 +28,9 @@ def settings_headings():
return get_headings((docs_path / "settings.rst").read_text(), "~") return get_headings((docs_path / "settings.rst").read_text(), "~")
@pytest.mark.parametrize("setting", app.SETTINGS) def test_settings_are_documented(settings_headings, subtests):
def test_settings_are_documented(settings_headings, setting): for setting in app.SETTINGS:
with subtests.test(setting=setting.name):
assert setting.name in settings_headings assert setting.name in settings_headings
@ -38,13 +39,13 @@ def plugin_hooks_content():
return (docs_path / "plugin_hooks.rst").read_text() return (docs_path / "plugin_hooks.rst").read_text()
@pytest.mark.parametrize( def test_plugin_hooks_are_documented(plugin_hooks_content, subtests):
"plugin", [name for name in dir(app.pm.hook) if not name.startswith("_")]
)
def test_plugin_hooks_are_documented(plugin, plugin_hooks_content):
headings = set() headings = set()
headings.update(get_headings(plugin_hooks_content, "-")) headings.update(get_headings(plugin_hooks_content, "-"))
headings.update(get_headings(plugin_hooks_content, "~")) headings.update(get_headings(plugin_hooks_content, "~"))
plugins = [name for name in dir(app.pm.hook) if not name.startswith("_")]
for plugin in plugins:
with subtests.test(plugin=plugin):
assert plugin in headings assert plugin in headings
hook_caller = getattr(app.pm.hook, plugin) hook_caller = getattr(app.pm.hook, plugin)
arg_names = [a for a in hook_caller.spec.argnames if a != "__multicall__"] arg_names = [a for a in hook_caller.spec.argnames if a != "__multicall__"]
@ -68,8 +69,10 @@ def documented_views():
return view_labels return view_labels
@pytest.mark.parametrize("view_class", [v for v in dir(app) if v.endswith("View")]) def test_view_classes_are_documented(documented_views, subtests):
def test_view_classes_are_documented(documented_views, view_class): view_classes = [v for v in dir(app) if v.endswith("View")]
for view_class in view_classes:
with subtests.test(view_class=view_class):
assert view_class in documented_views assert view_class in documented_views
@ -85,9 +88,10 @@ def documented_table_filters():
} }
@pytest.mark.parametrize("filter", [f.key for f in Filters._filters]) def test_table_filters_are_documented(documented_table_filters, subtests):
def test_table_filters_are_documented(documented_table_filters, filter): for f in Filters._filters:
assert filter in documented_table_filters with subtests.test(filter=f.key):
assert f.key in documented_table_filters
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@ -101,8 +105,9 @@ def documented_fns():
} }
@pytest.mark.parametrize("fn", utils.functions_marked_as_documented) def test_functions_marked_with_documented_are_documented(documented_fns, subtests):
def test_functions_marked_with_documented_are_documented(documented_fns, fn): for fn in utils.functions_marked_as_documented:
with subtests.test(fn=fn.__name__):
assert fn.__name__ in documented_fns assert fn.__name__ in documented_fns