mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-13 19:59:37 +08:00
change: build python plugin
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Release History
|
||||
|
||||
## v4.1.0 (2022-05-28)
|
||||
## v4.1.0 (2022-05-29)
|
||||
|
||||
- feat: add `wiki` sub-command to open httprunner website
|
||||
- feat: add `build` sub-command for function plugin
|
||||
|
||||
@@ -38,4 +38,4 @@ Copyright 2017 debugtalk
|
||||
* [hrp startproject](hrp_startproject.md) - create a scaffold project
|
||||
* [hrp wiki](hrp_wiki.md) - visit https://httprunner.com
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -42,4 +42,4 @@ hrp boom [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -28,4 +28,4 @@ hrp build $path ... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -22,4 +22,4 @@ hrp convert $path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -24,4 +24,4 @@ hrp har2case $har_path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -16,4 +16,4 @@ hrp pytest $path ... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -35,4 +35,4 @@ hrp run $path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -21,4 +21,4 @@ hrp startproject $project_name [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -16,4 +16,4 @@ hrp wiki [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 28-May-2022
|
||||
###### Auto generated by spf13/cobra on 29-May-2022
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"project_name": "demo-empty-project",
|
||||
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-empty-project",
|
||||
"create_time": "2022-05-28T21:41:06.430799+08:00",
|
||||
"create_time": "2022-05-29T00:19:34.824392+08:00",
|
||||
"hrp_version": "v4.1.0"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"project_name": "demo-with-go-plugin",
|
||||
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-go-plugin",
|
||||
"create_time": "2022-05-28T21:41:04.688435+08:00",
|
||||
"create_time": "2022-05-29T00:19:33.056663+08:00",
|
||||
"hrp_version": "v4.1.0"
|
||||
}
|
||||
75
examples/demo-with-py-plugin/debugtalk_gen.py
Normal file
75
examples/demo-with-py-plugin/debugtalk_gen.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# NOTE: Generated By hrp v4.1.0, 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()
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"project_name": "demo-with-py-plugin",
|
||||
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-py-plugin",
|
||||
"create_time": "2022-05-28T21:41:04.822656+08:00",
|
||||
"create_time": "2022-05-29T00:19:33.203339+08:00",
|
||||
"hrp_version": "v4.1.0"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"project_name": "demo-without-plugin",
|
||||
"project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-without-plugin",
|
||||
"create_time": "2022-05-28T21:41:06.311412+08:00",
|
||||
"create_time": "2022-05-29T00:19:34.698757+08:00",
|
||||
"hrp_version": "v4.1.0"
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/httprunner/funplugin"
|
||||
@@ -35,21 +34,6 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st
|
||||
// TODO: move pluginDir to funplugin
|
||||
pluginDir = filepath.Dir(pluginPath)
|
||||
|
||||
// compatible the format of debugtalk.py with v2/v3
|
||||
ext := filepath.Ext(pluginPath)
|
||||
if ext == ".py" {
|
||||
// skip if only debugtalk_gen.py exists
|
||||
if !strings.HasSuffix(pluginPath, "debugtalk_gen.py") {
|
||||
genPyPluginPath := filepath.Join(pluginDir, "debugtalk_gen.py")
|
||||
err = build.Run(pluginPath, genPyPluginPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf(fmt.Sprintf("failed to build %s", pluginPath))
|
||||
return
|
||||
}
|
||||
pluginPath = genPyPluginPath
|
||||
}
|
||||
}
|
||||
|
||||
// found plugin file
|
||||
plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn))
|
||||
if err != nil {
|
||||
@@ -80,7 +64,7 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st
|
||||
}
|
||||
|
||||
func locatePlugin(path string) (pluginPath string, err error) {
|
||||
// priority: hashicorp plugin (debugtalk.bin > debugtalk.py > debugtalk_gen.py) > go plugin (debugtalk.so)
|
||||
// priority: hashicorp plugin (debugtalk.bin > debugtalk.py) > go plugin (debugtalk.so)
|
||||
|
||||
pluginPath, err = locateFile(path, hashicorpGoPluginFile)
|
||||
if err == nil {
|
||||
@@ -89,12 +73,15 @@ func locatePlugin(path string) (pluginPath string, err error) {
|
||||
|
||||
pluginPath, err = locateFile(path, debugtalkPyFile)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
pluginPath, err = locateFile(path, hashicorpPyPluginFile)
|
||||
if err == nil {
|
||||
return
|
||||
// convert debugtalk.py to debugtalk_gen.py
|
||||
// register funppy plugin
|
||||
genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), hashicorpPyPluginFile)
|
||||
err = build.Run(pluginPath, genPyPluginPath)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed")
|
||||
return
|
||||
}
|
||||
return genPyPluginPath, nil
|
||||
}
|
||||
|
||||
pluginPath, err = locateFile(path, goPluginFile)
|
||||
|
||||
Reference in New Issue
Block a user