Skip to content

Keep a developer's real .env out of test_load_env_reads_environment - #22

Open
edmiidz wants to merge 1 commit into
ethanplusai:mainfrom
edmiidz:fix/test-env-isolation
Open

edmiidz wants to merge 1 commit into
ethanplusai:mainfrom
edmiidz:fix/test-env-isolation

Conversation

@edmiidz

@edmiidz edmiidz commented Oct 16, 2026

Copy link
Copy Markdown

Problem

test_load_env_reads_environment deletes HUNTER_API_KEY from the environment, then calls load_env(). load_env() calls load_dotenv(), which finds the repo's .env and loads it back in. So on any machine where .env has a real Hunter key:

  • the test fails (assert env.hunter_api_key == ""), and
  • pytest prints the full key in the assertion diff, where it can end up in terminal scrollback, CI logs or a pasted bug report.

CI has no .env, so CI passes. The failure only appears locally, once a key is set.

Fix

Stub harvey.config.load_dotenv inside the test, so it only sees the variables it sets itself. That's 2 lines, and no production code changes.

Testing

  • pytest -q tests/test_config_extra.py: 18 passed, with a real HUNTER_API_KEY in .env. It failed before this change.
  • Full suite: 545 passed, 22 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B4tcpnvC8VAkRoRkM7JWNF

…ment

load_env() calls load_dotenv(), which finds the repo's .env. With a real
HUNTER_API_KEY in it the test fails, and pytest prints the key in the
assertion diff. Stub load_dotenv so the test only sees what it sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B4tcpnvC8VAkRoRkM7JWNF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant