def test_expect_passes(): test_object = TestClass() expect(test_object).method.with_args( any_string.containing('bob') ) test_object.method('bob barker')
def test_allow_can_fail(): test_object = TestClass() allow(test_object).method.with_args( any_string.containing('todd') ) with pytest.raises(UnallowedMethodCallError): test_object.method('bob barker')
class TestContaining(object): test_obj = any_string.containing('abc') def test_string_contains_substring(self): assert self.test_obj == '123 abc 456' def test_string_does_not_contain_substring(self): assert not self.test_obj == '123 ac 456' def test_representation(self): expected = (r"Any instance of <(type|class) '(basestring|str)'> " r"containing: abc") assert re.match(expected, str(self.test_obj)) assert re.match('<Equals {}>'.format(expected), repr(self.test_obj))
def test_order_of_test_does_not_matter(): assert '123 abc 456' == any_string.containing('abc')
def test_allow_can_fail(): test_object = TestClass() allow(test_object).method.with_args(any_string.containing('todd')) with pytest.raises(UnallowedMethodCallError): test_object.method('bob barker')
def test_expect_passes(): test_object = TestClass() expect(test_object).method.with_args(any_string.containing('bob')) test_object.method('bob barker')