![](/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.