test: The exception on the pytest ExceptionInfo object can be accessed on the value attribute.

This commit is contained in:
Usman Khalid
2021-03-03 01:03:36 +05:00
parent 6af0eb5c28
commit 7441702ade
4 changed files with 4 additions and 4 deletions

View File

@@ -77,7 +77,7 @@ class TestSafeExec(unittest.TestCase): # lint-amnesty, pylint: disable=missing-
g = {}
with pytest.raises(SafeExecException) as cm:
safe_exec("1/0", g)
assert 'ZeroDivisionError' in text_type(cm.exception)
assert 'ZeroDivisionError' in text_type(cm.value)
class TestSafeOrNot(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring

View File

@@ -798,7 +798,7 @@ class StringResponseTest(ResponseTest): # pylint: disable=missing-class-docstri
problem = self.build_problem(answer="a2", case_sensitive=False, regexp=True, additional_answers=['?\\d?'])
with pytest.raises(Exception) as cm:
self.assert_grade(problem, "a3", "correct")
exception_message = text_type(cm.exception)
exception_message = text_type(cm.value)
assert 'nothing to repeat' in exception_message
def test_hints(self):

View File

@@ -451,7 +451,7 @@ class ProctoringProviderTestCase(unittest.TestCase):
with pytest.raises(ValueError) as context_manager:
self.proctoring_provider.from_json(provider)
assert context_manager.exception.args[0] ==\
assert context_manager.value.args[0] ==\
[f'The selected proctoring provider, {provider},'
f' is not a valid provider. Please select from one of {allowed_proctoring_providers}.']

View File

@@ -337,7 +337,7 @@ class GraderTest(unittest.TestCase):
def test_grader_with_invalid_conf(self, invalid_conf, expected_error_message):
with pytest.raises(ValueError) as error:
graders.grader_from_conf([invalid_conf])
assert expected_error_message in text_type(error.exception)
assert expected_error_message in text_type(error.value)
@ddt.ddt