Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from agent_build_kit import claude_account, forges, orchestration, sandboxes
from agent_build_kit import config as config_module
from agent_build_kit import installation as installation_module
from agent_build_kit import settings as settings_module
from agent_build_kit.cli import doctor
from agent_build_kit.cli import pipeline as pipeline_cli
from agent_build_kit.config import RepoConfig, WorkspaceConfig
Expand Down Expand Up @@ -83,6 +84,22 @@ def build_session(new_session_id: Callable[[], str]) -> str:
return new_session_id()


@pytest.fixture(autouse=True)
def settings_restored() -> Iterator[None]:
"""Every test ends with the settings it started with.

`settings.reload` writes the process-wide object in place, field by field, and loading an
installation or running the doctor calls it. `monkeypatch.setenv` restores the environment
but not the fields a reload wrote from it, so a later test on the same worker would read
the earlier one's value."""
before = settings_module.settings.model_dump()
env_file = settings_module.loaded_env_file
yield
for name, value in before.items():
setattr(settings_module.settings, name, value)
settings_module.loaded_env_file = env_file


@pytest.fixture(autouse=True)
def no_checkout_env_file(monkeypatch: pytest.MonkeyPatch) -> None:
"""A developer's ignored `.env` is not part of the suite: the lookup treats the checkout's
Expand Down
8 changes: 6 additions & 2 deletions tests/forges/test_github_api_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

Read off the requests that reach the stand-in host (their URLs). The forge reads the
setting from the settings object; the doctor loads the installation, which re-reads
the settings from the environment, so its tests set the environment variable.
the settings from the environment, so its tests set the environment variable. The `token`
fixture undoes that environment and reloads the settings afterwards, so a doctor test
leaves nothing for a forge test.
"""

from __future__ import annotations
Expand All @@ -19,7 +21,7 @@
from agent_build_kit.forges.base import RepoId
from agent_build_kit.forges.github import GitHubForge
from agent_build_kit.forges.transport import clear_credentials
from agent_build_kit.settings import settings
from agent_build_kit.settings import reload, settings
from tests.cli.test_doctor import Answers, which_all
from tests.factories import init_repo
from tests.forges.conftest import GH_TOKEN
Expand All @@ -37,6 +39,8 @@ def token(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
clear_credentials()
yield
clear_credentials()
monkeypatch.undo()
reload(None)


def created() -> httpx.Response:
Expand Down