Here is my Python code.
try: ct("table_that_does_not_exist", "database_that_does_not_exists")
except r.errors.ReqlOpFailedError as e: self.fail()
ct is a function to check if a table is exist in a database. ct returns True if a table exists in the database and False for otherwise.
try: ct("table_that_does_not_exist", "database_that_does_not_exists") is trying to check a non-existent table in a non-existent database. This should returns an error of this.
rethinkdb.errors.ReqlOpFailedError: Database `database_that_does_not_exists` does not exist in:
r.db('database_that_does_not_exists').table_list().contains('table_that_does_not_exist')
However, the error is somewhat not capture in except r.errors.ReqlOpFailedError as e: self.fail() and returns an AssertionError.
I expect this to pass the test, since ct("table_that_does_not_exist", "database_that_does_not_exists") will return r.errors.ReqlOpFailedError. But I got this instead.
======================================================================
FAIL: test_check_table (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 61, in test_check_table
try: ct("table_that_does_not_exist", "database_that_does_not_exists")
rethinkdb.errors.ReqlOpFailedError: Database `database_that_does_not_exists` does not exist in:
r.db('database_that_does_not_exists').table_list().contains('table_that_does_not_exist')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 62, in test_check_table
except r.errors.ReqlOpFailedError as e: self.fail()
AssertionError
----------------------------------------------------------------------
Ran 7 tests in 0.050s
FAILED (failures=1)
The error is match but not proceed through except.
What is wrong with my test?
unittestin Python 3.5.self.fail()to do?r.errors.ReqlOpFailedErrorhappens.