![](/img/trans.png)
[英]How to write python tornado test to assert the ioloop has shutdown?
[英]how to write a custom assert Python
我计划根据要测试的部分代码将一个大的测试文件拆分为较小的测试。 我为我的一项测试提供了一个自定义断言函数。 如果将它们拆分为单独的文件,应如何将它们导入其他测试文件。
TestSchemacase:
class TestSchemaCase(unittest.TestCase):
"""
This will test our schema against the JSONTransformer output
just to make sure the schema matches the model
"""
# pylint: disable=too-many-public-methods
_base_dir = os.path.realpath(os.path.dirname(__file__))
def assertJSONValidates(self, schema, data):
"""
This function asserts the validation works as expected
Args:
schema(dict): The schema to test against
data(dict): The data to validate using the schema
"""
# pylint: disable=invalid-name
validator = jsonschema.Draft4Validator(schema)
self.assertIsNone(validator.validate(data))
def assertJSONValidateFails(self, schema, data):
"""
This function will assertRaises an ValidationError Exception
is raised.
Args:
schema(dict): The schema to validate from
data(dict): The data to validate using the schema
"""
# pylint: disable=invalid-name
validator = jsonschema.Draft4Validator(schema)
with self.assertRaises(jsonschema.ValidationError):
validator.validate(data)
我的问题是1。 当我尝试导入它们时,出现导入错误,找不到模块名称。 我打破了TestValidation提到的小文件。 2.我知道我可以在assertJSONValidateFails中引发Validation错误,但是如果通过验证,我应该返回什么。
tests/schema
├── TestSchemaCase.py
├── TestValidation.py
├── __init__.py
└── models
├── Fields
│ ├── TestImplemen.py
│ ├── TestRes.py
│ └── __init__.py
├── Values
│ ├── TestInk.py
│ ├── TestAlue.py
│ └── __init__.py
└── __init__.py
3.这是我们应该如何继承它们? 类TestRes(unittest.TestCase,TestSchemaCase):
谢谢你的时间。 对不起,大帖子
我确实看到了该帖子,但这并不能解决问题。
我建议使用不会强迫您将测试放在pytest之类的测试框架中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.