mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 19:47:14 +08:00
refactor: EnsurePython3Venv
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
)
|
||||
|
||||
var buildCmd = &cobra.Command{
|
||||
@@ -19,11 +17,6 @@ var buildCmd = &cobra.Command{
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := builtin.PrepareVenv(venv)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("prepare python3 venv failed")
|
||||
return err
|
||||
}
|
||||
return hrp.BuildPlugin(args[0], output)
|
||||
},
|
||||
}
|
||||
|
||||
+7
-2
@@ -2,12 +2,14 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/convert"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
var convertCmd = &cobra.Command{
|
||||
@@ -35,9 +37,12 @@ var convertCmd = &cobra.Command{
|
||||
flagCount++
|
||||
outputType = convert.OutputTypePyTest
|
||||
|
||||
err := builtin.PrepareVenv(venv)
|
||||
packages := []string{
|
||||
fmt.Sprintf("httprunner==%s", version.VERSION),
|
||||
}
|
||||
_, err := builtin.EnsurePython3Venv(venv, packages...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("prepare python3 venv failed")
|
||||
log.Error().Err(err).Msg("python3 venv is not ready")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,11 +1,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/pytest"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
var pytestCmd = &cobra.Command{
|
||||
@@ -17,9 +20,12 @@ var pytestCmd = &cobra.Command{
|
||||
},
|
||||
DisableFlagParsing: true, // allow to pass any args to pytest
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := builtin.PrepareVenv(venv)
|
||||
packages := []string{
|
||||
fmt.Sprintf("httprunner==%s", version.VERSION),
|
||||
}
|
||||
_, err := builtin.EnsurePython3Venv(venv, packages...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("prepare python3 venv failed")
|
||||
log.Error().Err(err).Msg("python3 venv is not ready")
|
||||
return err
|
||||
}
|
||||
return pytest.RunPytest(args)
|
||||
|
||||
Reference in New Issue
Block a user