mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
refactor: run tests with pytest
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/httprunner/funplugin/shared"
|
||||
"github.com/httprunner/httprunner/hrp/internal/json"
|
||||
)
|
||||
|
||||
@@ -76,6 +77,21 @@ func FormatResponse(raw interface{}) interface{} {
|
||||
return formattedResponse
|
||||
}
|
||||
|
||||
func EnsurePython3Venv(packages ...string) (string, error) {
|
||||
// create python venv
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "get user home dir failed")
|
||||
}
|
||||
venvDir := filepath.Join(home, ".hrp", "venv")
|
||||
python3, err := shared.EnsurePython3Venv(venvDir, packages...)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "ensure python venv failed")
|
||||
}
|
||||
|
||||
return python3, nil
|
||||
}
|
||||
|
||||
func ExecCommand(cmd *exec.Cmd, cwd string) error {
|
||||
log.Info().Str("cmd", cmd.String()).Str("cwd", cwd).Msg("exec command")
|
||||
cmd.Dir = cwd
|
||||
|
||||
@@ -6,10 +6,18 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/hrp/internal/builtin"
|
||||
)
|
||||
|
||||
func RunPytest(args []string) error {
|
||||
cmd := exec.Command("pytest", args...)
|
||||
python3, err := builtin.EnsurePython3Venv("httprunner")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ensure python venv failed")
|
||||
}
|
||||
|
||||
args = append([]string{"-m", "httprunner", "run"}, args...)
|
||||
cmd := exec.Command(python3, args...)
|
||||
log.Info().Str("cmd", cmd.String()).Msg("run pytest")
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
@@ -178,13 +178,7 @@ func createPythonPlugin(projectName string) error {
|
||||
return errors.Wrap(err, "copy file failed")
|
||||
}
|
||||
|
||||
// create python venv
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get user home dir failed")
|
||||
}
|
||||
venvDir := filepath.Join(home, ".hrp", "venv")
|
||||
_, err = shared.EnsurePython3Venv(venvDir)
|
||||
_, err = builtin.EnsurePython3Venv(fmt.Sprintf("funppy==%s", shared.Version))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ensure python venv failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user