kopf
kopf copied to clipboard
Mocking env vars with KOPF
Keywords
environment variable, env var, mocking, mock
Problem
I am attempting to mock a env var. I am using the below code.
async def test_migrate_mode(mocker):
with mock.patch.dict(os.environ, {'MIGRATE_MODE': 'TRUE'}):
print('MIGRATE', os.getenv('MIGRATE_MODE'))
which prints MIGRATE TRUE
However when I run the operator with this value printed, I get the wrong value. So the test first tests the right value then when it runs the KopfRunner
it has the wrong value.
Migrate Mode is set to None
How do I set an environment variable for a specific test. We're using pytest test_v1alpha1.py -v -s -k test_migrate_mode
to test.