delayed-assert
delayed-assert copied to clipboard
Make caller verification optional.
Assume the following code,
def verify_1(self):
expect(not False, "False 1")
def verify_2(self):
expect( not False, "False 2")
def test_delete(self):
self.verify_1()
some code
self.verify_2()
some code
assert_expectations()
It is passing with the existing code but I want to assert only outside. Is there any way the caller stack verification to be skipped? using assert_expectations inside each and every method kind of defeats the purpose.
You can use like below example to avoid calling assert_expectations()
@delayed_assert.assert_all()
def testDecorator(self):
expect('five' == 'Six', 'String do not match')
expect([5,2] == [3,4], 'List item do not match')
expect([3,4] == [3,4], 'This message wont be printed')
# No need to call delayed_assert.assert_expectations() when decorator is used
def testContextManeger(self):
with delayed_assert.assert_all():
expect('four' == 'Six', 'String do not match')
expect([5,2] == [3,4], 'List item do not match')
expect([3,4] == [3,4], 'This message wont be printed')
# No need to call delayed_assert.assert_expectations() when using context maneger is used
So for your code example, it would be
def verify_1(self):
expect(not False, "False 1")
def verify_2(self):
expect( not False, "False 2")
@delayed_assert.assert_all()
def test_delete(self):
self.verify_1()
some code
self.verify_2()
some code
If this doesn't fix your problem please provide the stack trace of what you are getting currently and what you expect it to be.
def verify_1(self):
delayed_assert.expect(False, "False 1")
def verify_2(self):
delayed_assert.expect(not False, "False 2")
@delayed_assert.assert_all()
def test_delete(self):
self.verify_1()
self.verify_2()
The above test case is passing even when the first expect is False. The problem is that the logs are rewritten for every new method the stack enters.
Use case: My use case is that there is a single test case from which various methods are called. Each of those methods verify one part of the test case. When I assert the expectations in the test case, even if one of the expects (inside any method) fails, I want the test case to fail.
I've made few changes to address this, Could please try after installing from master as
pip install git+https://github.com/pr4bh4sh/delayed-assert
This fix is working fine.. Can we have a build with a version number ? Thanks In Advance..
the current fix will break backward compatibility, so can't be released in the current state. It will need a major refactor before I can release it. For now you can install it directly from master in your project as said above or put below in your requirement.txt file
-e git+https://github.com/pr4bh4sh/delayed-assert.git@93da91459ea2a1fae0876e3628a53de80a702581#egg=delayed-assert
if you use protocol other than https refer https://pip.pypa.io/en/latest/reference/pip_install/#git
Yeah.. Thank you.. Can you also update here once this update is released ?