mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 15:01:22 +08:00
Merge pull request #1330 from xucong053/master
fix: failed to regenerate .debugtalk_gen.py correctly
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
## v4.1.1 (2022-05-31)
|
## v4.1.1 (2022-05-31)
|
||||||
- fix: failed to build debugtalk.go without go.mod
|
- fix: failed to build debugtalk.go without go.mod
|
||||||
- fix: avoid to escape from html special characters like '&'
|
- fix: avoid to escape from html special characters like '&' in converted JSON testcase
|
||||||
|
- fix: display the full step name when referencing testcase in html report
|
||||||
|
- fix: failed to regenerate debugtalk_gen.go and .debugtalk_gen.py correctly
|
||||||
|
|
||||||
## v4.1.0 (2022-05-29)
|
## v4.1.0 (2022-05-29)
|
||||||
|
|
||||||
|
|||||||
16
hrp/build.go
16
hrp/build.go
@@ -155,7 +155,7 @@ func (t *TemplateContent) parsePyContent(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TemplateContent) genDebugTalk(path string, templ string) error {
|
func (t *TemplateContent) genDebugTalk(path string, templ string) error {
|
||||||
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0o666)
|
file, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("open file failed")
|
log.Error().Err(err).Msg("open file failed")
|
||||||
return err
|
return err
|
||||||
@@ -262,7 +262,7 @@ func buildPy(path string, output string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate debugtalk.py
|
// generate .debugtalk_gen.py
|
||||||
if output == "" {
|
if output == "" {
|
||||||
dir, _ := os.Getwd()
|
dir, _ := os.Getwd()
|
||||||
output = filepath.Join(dir, PluginPySourceGenFile)
|
output = filepath.Join(dir, PluginPySourceGenFile)
|
||||||
@@ -270,17 +270,7 @@ func buildPy(path string, output string) error {
|
|||||||
output = filepath.Join(output, PluginPySourceGenFile)
|
output = filepath.Join(output, PluginPySourceGenFile)
|
||||||
}
|
}
|
||||||
err = templateContent.genDebugTalk(output, pyTemplate)
|
err = templateContent.genDebugTalk(output, pyTemplate)
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure funppy in .env
|
|
||||||
_, err = builtin.EnsurePython3Venv("funppy")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildPlugin(path string, output string) (err error) {
|
func BuildPlugin(path string, output string) (err error) {
|
||||||
|
|||||||
75
hrp/internal/scaffold/templates/plugin/.debugtalk_gen.py
Normal file
75
hrp/internal/scaffold/templates/plugin/.debugtalk_gen.py
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# NOTE: Generated By hrp v4.1.1, DO NOT EDIT!
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import time
|
||||||
|
import funppy
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_agent():
|
||||||
|
return "hrp/funppy"
|
||||||
|
|
||||||
|
|
||||||
|
def sleep(n_secs):
|
||||||
|
time.sleep(n_secs)
|
||||||
|
|
||||||
|
|
||||||
|
def sum(*args):
|
||||||
|
result = 0
|
||||||
|
for arg in args:
|
||||||
|
result += arg
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def sum_ints(*args: List[int]) -> int:
|
||||||
|
result = 0
|
||||||
|
for arg in args:
|
||||||
|
result += arg
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def sum_two_int(a: int, b: int) -> int:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
|
||||||
|
def sum_two_string(a: str, b: str) -> str:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
|
||||||
|
def sum_strings(*args: List[str]) -> str:
|
||||||
|
result = ""
|
||||||
|
for arg in args:
|
||||||
|
result += arg
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def concatenate(*args: List[str]) -> str:
|
||||||
|
result = ""
|
||||||
|
for arg in args:
|
||||||
|
result += str(arg)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def setup_hook_example(name):
|
||||||
|
logging.warning("setup_hook_example")
|
||||||
|
return f"setup_hook_example: {name}"
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_hook_example(name):
|
||||||
|
logging.warning("teardown_hook_example")
|
||||||
|
return f"teardown_hook_example: {name}"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
funppy.register("get_user_agent", get_user_agent)
|
||||||
|
funppy.register("sleep", sleep)
|
||||||
|
funppy.register("sum", sum)
|
||||||
|
funppy.register("sum_ints", sum_ints)
|
||||||
|
funppy.register("sum_two_int", sum_two_int)
|
||||||
|
funppy.register("sum_two_string", sum_two_string)
|
||||||
|
funppy.register("sum_strings", sum_strings)
|
||||||
|
funppy.register("concatenate", concatenate)
|
||||||
|
funppy.register("setup_hook_example", setup_hook_example)
|
||||||
|
funppy.register("teardown_hook_example", teardown_hook_example)
|
||||||
|
funppy.serve()
|
||||||
16
hrp/internal/scaffold/templates/plugin/debugtalk_gen.go
Normal file
16
hrp/internal/scaffold/templates/plugin/debugtalk_gen.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// NOTE: Generated By hrp v4.1.1, DO NOT EDIT!
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/httprunner/funplugin/fungo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fungo.Register("SumTwoInt", SumTwoInt)
|
||||||
|
fungo.Register("SumInts", SumInts)
|
||||||
|
fungo.Register("Sum", Sum)
|
||||||
|
fungo.Register("SetupHookExample", SetupHookExample)
|
||||||
|
fungo.Register("TeardownHookExample", TeardownHookExample)
|
||||||
|
fungo.Register("GetUserAgent", GetUserAgent)
|
||||||
|
fungo.Serve()
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/httprunner/funplugin"
|
"github.com/httprunner/funplugin"
|
||||||
@@ -34,6 +35,17 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, err error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(pluginPath, ".py") {
|
||||||
|
// register funppy plugin
|
||||||
|
genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), PluginPySourceGenFile)
|
||||||
|
err = BuildPlugin(pluginPath, genPyPluginPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
pluginPath = genPyPluginPath
|
||||||
|
}
|
||||||
|
|
||||||
// found plugin file
|
// found plugin file
|
||||||
plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn))
|
plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -73,14 +85,7 @@ func locatePlugin(path string) (pluginPath string, err error) {
|
|||||||
|
|
||||||
pluginPath, err = locateFile(path, PluginPySourceFile)
|
pluginPath, err = locateFile(path, PluginPySourceFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// register funppy plugin
|
return
|
||||||
genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), PluginPySourceGenFile)
|
|
||||||
err = BuildPlugin(pluginPath, genPyPluginPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return genPyPluginPath, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginPath, err = locateFile(path, PluginGoBuiltFile)
|
pluginPath, err = locateFile(path, PluginGoBuiltFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user