mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-13 00:11:28 +08:00
refactor: check if is function
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import types
|
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
|
|
||||||
@@ -199,9 +198,3 @@ def is_testcase_path(path):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_function(item):
|
|
||||||
""" Takes item object, returns True if it is a function.
|
|
||||||
"""
|
|
||||||
return isinstance(item, types.FunctionType)
|
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import csv
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import types
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from httprunner import builtin
|
from httprunner import builtin
|
||||||
from httprunner import exceptions, logger, utils
|
from httprunner import exceptions, logger, utils
|
||||||
from httprunner.loader.check import is_function
|
|
||||||
from httprunner.loader.locate import get_project_working_directory
|
from httprunner.loader.locate import get_project_working_directory
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -206,7 +206,7 @@ def load_module_functions(module):
|
|||||||
module_functions = {}
|
module_functions = {}
|
||||||
|
|
||||||
for name, item in vars(module).items():
|
for name, item in vars(module).items():
|
||||||
if is_function(item):
|
if isinstance(item, types.FunctionType):
|
||||||
module_functions[name] = item
|
module_functions[name] = item
|
||||||
|
|
||||||
return module_functions
|
return module_functions
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ from httprunner.loader import check
|
|||||||
|
|
||||||
class TestLoaderCheck(unittest.TestCase):
|
class TestLoaderCheck(unittest.TestCase):
|
||||||
|
|
||||||
def test_is_function(self):
|
|
||||||
func = lambda x: x + 1
|
|
||||||
self.assertTrue(check.is_function(func))
|
|
||||||
self.assertTrue(check.is_function(check.is_testcase))
|
|
||||||
|
|
||||||
def test_is_testcases(self):
|
def test_is_testcases(self):
|
||||||
data_structure = "path/to/file"
|
data_structure = "path/to/file"
|
||||||
self.assertFalse(check.is_testcases(data_structure))
|
self.assertFalse(check.is_testcases(data_structure))
|
||||||
|
|||||||
Reference in New Issue
Block a user