【发布时间】:2022-01-13 22:02:56
【问题描述】:
我有以下类,我想为它写几个单元测试:
class JsonSchemaValidator:
def __init__(self, json_file):
self.json_file = json_file
self.schema = json.load(open(json_file))
def check_json_schema(self):
print(self.json_file)
Draft3Validator.check_schema(self.schema)
如上所示,该类有self.json_file 和self.schema 两个实例,我想为每个测试定义架构。如何设置测试,以便可以为每个测试用例定义架构?
class TestValidator(TestCase):
def test_check_json_schema1(self):
schema = {
"type": "object",
"properties": {
"key1": {"type": "string"}
},
}
actual = JsonSchemaValidator.check_json_schema() ##??
self.assertIsNone(actual)
def test_check_json_schema2(self):
schema = {
"type": "object",
"properties": {
"key2": {"type": "SOME_TYPE"}
},
}
self.assertRaises(SchemaError, JsonSchemaValidator.check_json_schema, schema) ##??
【问题讨论】:
标签: python class python-unittest python-class