mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-21 20:42:25 +08:00
feat: report GA4 events for hrp cmd
This commit is contained in:
@@ -2,12 +2,15 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/pytest"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
@@ -19,11 +22,20 @@ var pytestCmd = &cobra.Command{
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
DisableFlagParsing: true, // allow to pass any args to pytest
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
startTime := time.Now()
|
||||
defer func() {
|
||||
sdk.SendGA4Event("hrp_pytest", map[string]interface{}{
|
||||
"args": strings.Join(args, "-"),
|
||||
"success": err == nil,
|
||||
"engagement_time_msec": time.Since(startTime).Milliseconds(),
|
||||
})
|
||||
}()
|
||||
|
||||
packages := []string{
|
||||
fmt.Sprintf("httprunner==%s", version.HttpRunnerMinimumVersion),
|
||||
}
|
||||
_, err := myexec.EnsurePython3Venv(venv, packages...)
|
||||
_, err = myexec.EnsurePython3Venv(venv, packages...)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("python3 venv is not ready")
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user