fix: convert postman to pytest

This commit is contained in:
debugtalk
2022-06-27 21:28:09 +08:00
parent bdd3aa9b4c
commit 7498a580b6
2 changed files with 10 additions and 5 deletions
+2 -2
View File
@@ -450,8 +450,8 @@ func ReadFile(path string) ([]byte, error) {
return file, nil return file, nil
} }
func GetOutputNameWithoutExtension(path string) string { func GetFileNameWithoutExtension(path string) string {
base := filepath.Base(path) base := filepath.Base(path)
ext := filepath.Ext(base) ext := filepath.Ext(base)
return base[0:len(base)-len(ext)] + "_test" return base[0 : len(base)-len(ext)]
} }
+8 -3
View File
@@ -168,7 +168,7 @@ type TCaseConverter struct {
} }
func (c *TCaseConverter) genOutputPath(suffix string) string { func (c *TCaseConverter) genOutputPath(suffix string) string {
outFileFullName := builtin.GetOutputNameWithoutExtension(c.SourcePath) + suffix outFileFullName := builtin.GetFileNameWithoutExtension(c.SourcePath) + "_test" + suffix
if c.OutputDir != "" { if c.OutputDir != "" {
return filepath.Join(c.OutputDir, outFileFullName) return filepath.Join(c.OutputDir, outFileFullName)
} else { } else {
@@ -179,8 +179,13 @@ func (c *TCaseConverter) genOutputPath(suffix string) string {
// convert TCase to pytest case // convert TCase to pytest case
func (c *TCaseConverter) ToPyTest() (string, error) { func (c *TCaseConverter) ToPyTest() (string, error) {
args := append([]string{"make"}, c.SourcePath) jsonPath, err := c.ToJSON()
err := builtin.ExecPython3Command("httprunner", args...) if err != nil {
return "", errors.Wrap(err, "convert to JSON case failed")
}
args := append([]string{"make"}, jsonPath)
err = builtin.ExecPython3Command("httprunner", args...)
if err != nil { if err != nil {
return "", err return "", err
} }