霍格沃兹测试开发学社
from genson import SchemaBuilder
builder = SchemaBuilder()
builder.add_object({"a":1,"b":"aaaa","c":"","d":None})
builder.add_object({"a":"1","b":"bbb","c":1})
print(builder.to_schema())
print(builder.to_json(indent=2))
from jsonschema import validate
def schema_validate(obj, schema):
try:
validate(instance=obj, schema=schema)
return True
except Exception as e:
# raise e
print(e)
return False
def test_validate():
_schema = json.load(open("demo_schema.json", encoding="utf-8"))
assert schema_validate({"a": "1", "b": 12, "c": 1}, _schema)
def query_db():
conn = pymysql.Connect(host="47.92.149.0", port=3366, database="test_db",
user="root", password="123456",
charset="utf8")
cursor = conn.cursor()
sql = "some sql'"
cursor.execute(sql)
print("行数:", cursor.rowcount)
# 获取行数
datas = cursor.fetchall()
print("查询到的数据为:", datas) # 获取多条数据
cursor.close()
conn.close()
return datas