mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 07:21:23 +08:00
feat #1342: support specify custom python3 venv
This commit is contained in:
@@ -54,6 +54,9 @@ var boomCmd = &cobra.Command{
|
||||
hrpBoomer.SetDisableKeepAlive(boomArgs.DisableKeepalive)
|
||||
hrpBoomer.SetDisableCompression(boomArgs.DisableCompression)
|
||||
hrpBoomer.SetClientTransport()
|
||||
if venv != "" {
|
||||
hrpBoomer.SetPython3Venv(venv)
|
||||
}
|
||||
hrpBoomer.EnableCPUProfile(boomArgs.CPUProfile, boomArgs.CPUProfileDuration)
|
||||
hrpBoomer.EnableMemoryProfile(boomArgs.MemoryProfile, boomArgs.MemoryProfileDuration)
|
||||
hrpBoomer.EnableGracefulQuit()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
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{
|
||||
@@ -17,6 +19,11 @@ 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)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package cmd
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -32,6 +34,12 @@ var convertCmd = &cobra.Command{
|
||||
if toPyTestFlag {
|
||||
flagCount++
|
||||
outputType = convert.OutputTypePyTest
|
||||
|
||||
err := builtin.PrepareVenv(venv)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("prepare python3 venv failed")
|
||||
return err
|
||||
}
|
||||
}
|
||||
if flagCount > 1 {
|
||||
return errors.New("please specify at most one conversion flag")
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -15,6 +17,11 @@ 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)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("prepare python3 venv failed")
|
||||
return err
|
||||
}
|
||||
return pytest.RunPytest(args)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ Copyright 2017 debugtalk`,
|
||||
var (
|
||||
logLevel string
|
||||
logJSON bool
|
||||
venv string
|
||||
)
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
@@ -55,6 +56,7 @@ var (
|
||||
func Execute() {
|
||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||
rootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
||||
rootCmd.PersistentFlags().StringVar(&venv, "venv", "", "specify python3 venv path")
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
|
||||
@@ -41,6 +41,9 @@ var runCmd = &cobra.Command{
|
||||
if pluginLogOn {
|
||||
runner.SetPluginLogOn()
|
||||
}
|
||||
if venv != "" {
|
||||
runner.SetPython3Venv(venv)
|
||||
}
|
||||
if proxyUrl != "" {
|
||||
runner.SetProxyUrl(proxyUrl)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ var scaffoldCmd = &cobra.Command{
|
||||
pluginType = scaffold.Py // default
|
||||
}
|
||||
|
||||
err := scaffold.CreateScaffold(args[0], pluginType, force)
|
||||
err := scaffold.CreateScaffold(args[0], pluginType, venv, force)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("create scaffold project failed")
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user