Skip to content

Commit 7dfc0a5

Browse files
committed
Update texampleTests.m
1 parent 57741c2 commit 7dfc0a5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tests/texampleTests.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
methods (TestClassSetup)
77
function setUpAndTearDowns(testCase)
88
openAIEnvVar = "OPENAI_KEY";
9-
key = getenv(openAIEnvVar);
10-
writelines("OPENAI_API_KEY="+key,".env");
9+
secretKey = getenv(openAIEnvVar);
10+
% Create an empty .env file because it is expected by our .mlx
11+
% example files
12+
writelines("",".env");
13+
14+
% Assign the value of the secret key to OPENAI_API_KEY using
15+
% the test fixture
16+
import matlab.unittest.fixtures.EnvironmentVariableFixture
17+
fixture = EnvironmentVariableFixture("OPENAI_API_KEY", secretKey);
18+
testCase.applyFixture(fixture);
1119

12-
testCase.addTeardown(@() delete(".env"));
13-
testCase.addTeardown(@() unsetenv("OPENAI_API_KEY"));
1420
testCase.addTeardown(@() iCloseAll());
1521
end
1622
end

0 commit comments

Comments
 (0)