With our tests, we use a fixture for handling creating/tearing down a test client:
@pytest.fixture
def client() -> Client:
with Client(app) as test_client:
yield test_client
Which theoretically should configure the environment variables defined in the config file when we call invoke.
What seems to be happening is that if we run our lambda function tests individually, the correct environment variables seem to be assigned, but if we run both of our lambda function tests in the same test session, only the first set of environment variables are configured (from the test that was invoked first) in both.
I haven't quite figured out if something is not being reset properly between tests, or if there's a bug in setting up the environment from the config in the case of per-lambda environment variables with the test client.
The issue is resolved if we monkeypatch the environment with the necessary variables.
We've been experimenting with chalice and generally have been pretty pleased, but we've run into an issue while writing tests with
pytest
.Our chalice app contains multiple lambda functions with per-lambda environment variables:
With our tests, we use a fixture for handling creating/tearing down a test client:
Which theoretically should configure the environment variables defined in the config file when we call
invoke
.What seems to be happening is that if we run our lambda function tests individually, the correct environment variables seem to be assigned, but if we run both of our lambda function tests in the same test session, only the first set of environment variables are configured (from the test that was invoked first) in both.
I haven't quite figured out if something is not being reset properly between tests, or if there's a bug in setting up the environment from the config in the case of per-lambda environment variables with the test client.
The issue is resolved if we monkeypatch the environment with the necessary variables.