Problem
Unit tests fail (15 failures) when .env.local environment variables are exported in the shell. This happens because .env.local overrides values that unit tests expect to be unset or at defaults:
PROVENANCE_GATEWAY_URL=http://localhost:8000 breaks test_default_url (expects production URL)
X402_PRIVATE_KEY being set breaks test_x402_status_shows_no_private_key and test_x402_balance_fails_without_private_key
- Real
X402_PRIVATE_KEY causes x402 client tests to bypass mocks and hit real Web3 providers
Current workaround
Run unit and integration tests separately:
# Unit tests — clean environment (no .env.local)
pytest --ignore=tests/test_integration.py
# Integration tests — need .env.local for wallet keys
export $(grep -v '^#' .env.local | xargs)
pytest tests/test_integration.py -v
Expected behavior
Unit tests should pass regardless of what environment variables are set, since they mock all external dependencies.
Possible solutions
- Fixture-based env isolation: Add a
conftest.py autouse fixture that saves and clears sensitive env vars (PROVENANCE_GATEWAY_URL, X402_PRIVATE_KEY, PROVENANCE_WALLET_KEY, etc.) before each unit test, restoring them after
monkeypatch in affected tests: Use monkeypatch.delenv() in the specific tests that assume unset env vars
- Reload config module: Mock or reload
config.py in unit tests so module-level os.getenv() calls pick up test values instead of shell env
Affected tests
| Test file |
Failures |
Cause |
test_gateway_client.py |
1 |
PROVENANCE_GATEWAY_URL override |
test_cli.py |
2 |
X402_PRIVATE_KEY set |
test_x402_client.py |
12 |
X402_PRIVATE_KEY bypasses mocks |
Problem
Unit tests fail (15 failures) when
.env.localenvironment variables are exported in the shell. This happens because.env.localoverrides values that unit tests expect to be unset or at defaults:PROVENANCE_GATEWAY_URL=http://localhost:8000breakstest_default_url(expects production URL)X402_PRIVATE_KEYbeing set breakstest_x402_status_shows_no_private_keyandtest_x402_balance_fails_without_private_keyX402_PRIVATE_KEYcauses x402 client tests to bypass mocks and hit real Web3 providersCurrent workaround
Run unit and integration tests separately:
Expected behavior
Unit tests should pass regardless of what environment variables are set, since they mock all external dependencies.
Possible solutions
conftest.pyautouse fixture that saves and clears sensitive env vars (PROVENANCE_GATEWAY_URL,X402_PRIVATE_KEY,PROVENANCE_WALLET_KEY, etc.) before each unit test, restoring them aftermonkeypatchin affected tests: Usemonkeypatch.delenv()in the specific tests that assume unset env varsconfig.pyin unit tests so module-levelos.getenv()calls pick up test values instead of shell envAffected tests
test_gateway_client.pyPROVENANCE_GATEWAY_URLoverridetest_cli.pyX402_PRIVATE_KEYsettest_x402_client.pyX402_PRIVATE_KEYbypasses mocks