mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-11 18:59:39 +08:00
fix #1308: load .env file as environment variables
This commit is contained in:
@@ -80,6 +80,16 @@ func (path *TestCasePath) ToTestCase() (*TestCase, error) {
|
||||
return nil, errors.Wrap(err, "failed to get project root dir")
|
||||
}
|
||||
|
||||
// load .env file
|
||||
dotEnvPath := filepath.Join(projectRootDir, ".env")
|
||||
if builtin.IsFilePathExists(dotEnvPath) {
|
||||
testCase.Config.Env = make(map[string]string)
|
||||
err = builtin.LoadFile(dotEnvPath, testCase.Config.Env)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load .env file")
|
||||
}
|
||||
}
|
||||
|
||||
for _, step := range tc.TestSteps {
|
||||
if step.API != nil {
|
||||
apiPath, ok := step.API.(string)
|
||||
|
||||
Reference in New Issue
Block a user