From a0bbbe8ffa7867f7bf7e1ba05a9362ce97e88085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Tue, 9 Jul 2019 12:33:57 +0200 Subject: [PATCH] Add the API documentation of ContractFail to the contracts topic --- docs/topics/contracts.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/topics/contracts.rst b/docs/topics/contracts.rst index 9337375bb..05b1d161b 100644 --- a/docs/topics/contracts.rst +++ b/docs/topics/contracts.rst @@ -69,7 +69,7 @@ create and load your own contracts in the project by using the 'myproject.contracts.ItemValidate': 10, } -Each contract must inherit from :class:`scrapy.contracts.Contract` and can +Each contract must inherit from :class:`~scrapy.contracts.Contract` and can override three methods: .. module:: scrapy.contracts @@ -102,9 +102,14 @@ override three methods: This allows processing the output of the callback. Iterators are converted listified before being passed to this hook. +Raise :class:`~scrapy.exceptions.ContractFail` from +:class:`~scrapy.contracts.Contract.pre_process` or +:class:`~scrapy.contracts.Contract.post_process` if expectations are not met: + +.. autoclass:: scrapy.exceptions.ContractFail + Here is a demo contract which checks the presence of a custom header in the -response received. Raise :class:`scrapy.exceptions.ContractFail` in order to -get the failures pretty printed:: +response received:: from scrapy.contracts import Contract from scrapy.exceptions import ContractFail