mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
feat: hrp convert testcases to pytest scripts
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/hrp"
|
||||
)
|
||||
|
||||
var convertCmd = &cobra.Command{
|
||||
Use: "convert $path...",
|
||||
Short: "convert JSON/YAML testcases to pytest/gotest scripts",
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !pytestFlag && !gotestFlag {
|
||||
return errors.New("please specify convertion type")
|
||||
}
|
||||
|
||||
var err error
|
||||
if gotestFlag {
|
||||
err = hrp.Convert2TestScripts("gotest", args...)
|
||||
} else {
|
||||
err = hrp.Convert2TestScripts("pytest", args...)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("convert test scripts failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
pytestFlag bool
|
||||
gotestFlag bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(convertCmd)
|
||||
convertCmd.Flags().BoolVar(&pytestFlag, "pytest", true, "convert to pytest scripts")
|
||||
convertCmd.Flags().BoolVar(&gotestFlag, "gotest", false, "convert to gotest scripts (TODO)")
|
||||
}
|
||||
Reference in New Issue
Block a user