mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
feat: support run testcases in specified folder path, including testcases in sub-folders
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
**go version**
|
**go version**
|
||||||
|
|
||||||
- feat: add `--profile` flag for har2case to support overwrite headers/cookies with specified yaml/json profile file
|
- feat: add `--profile` flag for har2case to support overwrite headers/cookies with specified yaml/json profile file
|
||||||
- feat: support run testcases in specified folder path
|
- feat: support run testcases in specified folder path, including testcases in sub folders
|
||||||
- change: integrate [sentry sdk][sentry sdk] for panic reporting and analysis
|
- change: integrate [sentry sdk][sentry sdk] for panic reporting and analysis
|
||||||
- change: lock funplugin version when creating scaffold project
|
- change: lock funplugin version when creating scaffold project
|
||||||
- fix: call referenced api/testcase with relative path
|
- fix: call referenced api/testcase with relative path
|
||||||
|
|||||||
+28
-26
@@ -10,7 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/fs"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@@ -219,40 +219,42 @@ func loadTestCases(iTestCases ...ITestCase) ([]*TestCase, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// iTestCase should be a TestCasePath, file path or folder path
|
// iTestCase should be a TestCasePath, file path or folder path
|
||||||
testCasePath, ok := iTestCase.(*TestCasePath)
|
tcPath, ok := iTestCase.(*TestCasePath)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("invalid iTestCase type")
|
return nil, errors.New("invalid iTestCase type")
|
||||||
}
|
}
|
||||||
|
|
||||||
casePaths := make([]*TestCasePath, 0)
|
casePath := tcPath.GetPath()
|
||||||
casePath := iTestCase.GetPath()
|
err := fs.WalkDir(os.DirFS(casePath), ".", func(path string, dir fs.DirEntry, e error) error {
|
||||||
if builtin.IsFolderPathExists(casePath) {
|
if dir == nil {
|
||||||
// folder path
|
// casePath is a file other than a dir
|
||||||
files, err := ioutil.ReadDir(casePath)
|
path = casePath
|
||||||
if err != nil {
|
} else if dir.IsDir() && path != "." && strings.HasPrefix(path, ".") {
|
||||||
return nil, errors.Wrap(err, "read dir failed")
|
// skip hidden folders
|
||||||
|
return fs.SkipDir
|
||||||
|
} else {
|
||||||
|
// casePath is a dir
|
||||||
|
path = filepath.Join(casePath, path)
|
||||||
}
|
}
|
||||||
for _, f := range files {
|
|
||||||
ext := filepath.Ext(f.Name())
|
|
||||||
if ext != ".yml" && ext != ".yaml" && ext != ".json" {
|
|
||||||
// ignore non-testcase files
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
path := TestCasePath(filepath.Join(casePath, f.Name()))
|
|
||||||
casePaths = append(casePaths, &path)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// file path
|
|
||||||
casePaths = append(casePaths, testCasePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, path := range casePaths {
|
// ignore non-testcase files
|
||||||
tc, err := path.ToTestCase()
|
ext := filepath.Ext(path)
|
||||||
|
if ext != ".yml" && ext != ".yaml" && ext != ".json" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// filtered testcases
|
||||||
|
testCasePath := TestCasePath(path)
|
||||||
|
tc, err := testCasePath.ToTestCase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Str("path", path.GetPath()).Msg("load testcase failed")
|
log.Error().Err(err).Str("path", path).Msg("load testcase failed")
|
||||||
return nil, errors.Wrap(err, "load testcase failed")
|
return errors.Wrap(err, "load testcase failed")
|
||||||
}
|
}
|
||||||
testCases = append(testCases, tc)
|
testCases = append(testCases, tc)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "read dir failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -296,13 +296,23 @@ func TestLoadTestCases(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load test cases from folder path, including sub folders
|
||||||
|
tc = TestCasePath("../examples/demo-with-py-plugin/")
|
||||||
|
testCases, err = loadTestCases(&tc)
|
||||||
|
if !assert.Nil(t, err) {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if !assert.Equal(t, len(testCases), 3) {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
// load test cases from single file path
|
// load test cases from single file path
|
||||||
tc = demoTestCaseWithPluginJSONPath
|
tc = demoTestCaseWithPluginJSONPath
|
||||||
testCases, err = loadTestCases(&tc)
|
testCases, err = loadTestCases(&tc)
|
||||||
if !assert.Nil(t, err) {
|
if !assert.Nil(t, err) {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
if !assert.Equal(t, len(testCases), 1) {
|
if !assert.Equal(t, 1, len(testCases)) {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ class GAClient(object):
|
|||||||
|
|
||||||
def __init__(self, tracking_id: Text):
|
def __init__(self, tracking_id: Text):
|
||||||
self.http_client = requests.Session()
|
self.http_client = requests.Session()
|
||||||
self.label = str(__version__)
|
self.label = f"v{__version__}"
|
||||||
self.common_params = {
|
self.common_params = {
|
||||||
'v': self.version,
|
'v': self.version,
|
||||||
'tid': tracking_id, # Tracking ID / Property ID, XX-XXXXXXX-X
|
'tid': tracking_id, # Tracking ID / Property ID, XX-XXXXXXX-X
|
||||||
|
|||||||
Reference in New Issue
Block a user