From 3accd5f12f9bd04b4ae12b5d1fe47597c0c68757 Mon Sep 17 00:00:00 2001 From: Nathaniel Ramm Date: Sun, 19 Apr 2026 00:01:03 +1000 Subject: [PATCH] fix(profiles): lazy-import pytest in descriptor_invariants_for MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Module-top `import pytest` in profiles/invariants.py crashes any env without pytest installed, because profiles/__init__.py eagerly imports the helper. That meant `import mountainash_settings` failed in any non-test env (downstream `dev` envs, production deploys). Moves `import pytest` inside descriptor_invariants_for itself. The helper still requires pytest to run, but merely importing `mountainash_settings` no longer does. Discovered while testing v26.4.1 setattr fix against mountainash-data's dev env — settings test env has pytest so `hatch run test:test` passed and masked the issue. Bumps version 26.4.1 → 26.4.2. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/mountainash_settings/__version__.py | 2 +- src/mountainash_settings/profiles/invariants.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mountainash_settings/__version__.py b/src/mountainash_settings/__version__.py index c4c67b1..861a6a3 100644 --- a/src/mountainash_settings/__version__.py +++ b/src/mountainash_settings/__version__.py @@ -1 +1 @@ -__version__="26.4.1" \ No newline at end of file +__version__="26.4.2" \ No newline at end of file diff --git a/src/mountainash_settings/profiles/invariants.py b/src/mountainash_settings/profiles/invariants.py index e8c7c8f..317a490 100644 --- a/src/mountainash_settings/profiles/invariants.py +++ b/src/mountainash_settings/profiles/invariants.py @@ -16,8 +16,6 @@ import typing as t -import pytest - from mountainash_settings.auth.base import AuthSpec from .registry import Registry @@ -31,6 +29,9 @@ def descriptor_invariants_for(registry: Registry) -> type: The returned class is named ``TestDescriptorInvariants_``. """ + # Lazy import: keeps ``mountainash_settings`` importable in non-test envs. + import pytest + entries = list(registry.descriptors.items()) ids = list(registry.descriptors.keys()) or [""]