Skip to content

Commit

Permalink
tests: Speed up stdlib tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed May 7, 2024
1 parent 77c4ea3 commit 141460f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions tests/test_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import sys
from contextlib import suppress
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Iterator

import pytest

from griffe.exceptions import LoadingError
from griffe.loader import GriffeLoader

if TYPE_CHECKING:
Expand All @@ -26,18 +27,24 @@ def _access_inherited_members(obj: Object | Alias) -> None:
_access_inherited_members(cls)


@pytest.mark.skipif(sys.version_info < (3, 10), reason="Python less than 3.10 does not have sys.stdlib_module_names")
def test_fuzzing_on_stdlib() -> None:
"""Run Griffe on the standard library."""
stblib_packages = sorted([m for m in sys.stdlib_module_names if not m.startswith("_")]) # type: ignore[attr-defined,unused-ignore]
@pytest.fixture(name="stdlib_loader", scope="session")
def fixture_stdlib_loader() -> Iterator[GriffeLoader]:
"""Yield a GriffeLoader instance.
loader = GriffeLoader()
for package in stblib_packages:
with suppress(ImportError):
loader.load(package)

loader.resolve_aliases(implicit=True, external=True)
During teardown, resolve aliases and access inherited members
to make sure that no exception is raised when computing MRO.
"""
loader = GriffeLoader(allow_inspection=False, store_source=False)
yield loader
loader.resolve_aliases(implicit=True, external=None)
for module in loader.modules_collection.members.values():
_access_inherited_members(module)

loader.stats()


@pytest.mark.skipif(sys.version_info < (3, 10), reason="Python less than 3.10 does not have sys.stdlib_module_names")
@pytest.mark.parametrize("mod", sorted([m for m in getattr(sys, "stdlib_module_names", ()) if not m.startswith("_")]))
def test_fuzzing_on_stdlib(stdlib_loader: GriffeLoader, mod: str) -> None:
"""Run Griffe on the standard library."""
with suppress(ImportError, LoadingError):
stdlib_loader.load(mod)

0 comments on commit 141460f

Please sign in to comment.