def test_disabled_contracts(self): contracts.disable_all() @contract def disabled(phrase): """ :type phrase: str """ return phrase # this should not throw w/ contracts disabled disabled(int(8)) contracts.enable_all() # this will still not throw because the disabled value is checked at decoration time only disabled(int(8)) @contract def enabled(phrase): """ :type phrase: str """ return phrase # a newly decorated function will throw with pytest.raises(exceptions.ContractNotRespected): enabled(int(8))
def enable_all(): """ Wraps PyContracts `enable_all() <http://andreacensi.github.io/contracts/api/contracts.html# module-contracts.enabling>`_ function. From the PyContracts documentation: "Enables all contract checks. Can be overridden by an environment variable" """ contracts.enable_all()
def setUp(self): contracts.enable_all()
def __exit__(self, type, value, traceback): enable_all()