Reputation: 1
Problem Summary: I am trying to import two python methods mentioned in another file and receiving the following error,
In Jupyter Notebook (another file named verify.ipynb), I have imported two methods mention within 'common.py' file
from xyzClassifier.constants import *
from xyzClassifier.utils.common import read_yaml, create_directories
Line 1, executed successfully, but when I try to execute both the line, following error shows,
AttributeError: 'TestCase' object has no attribute 'assertRaisesRegexp'Cell Execution Error
IDE, OS and Python version: VS Code in macOS and python 3.12.5
Problem Steps and Code snippet:
but when I try to import those methods in one of the cell of Jupyter notebook (the .ipynb file) by
from xyzClassifier.utils.common import read_yaml, create_directories,
it is throwing the error, 'AttributeError: 'TestCase' object has no attribute 'assertRaisesRegexp'Cell Execution Error'
What have I done:
I am expecting these two methods will import successfully. I tried to put those two methods inside try, except block and throwing and catching the exception like, but nothing worked.
except assertRaisesRegexp as arr:
raise arr
except Exception as e:
raise e
Detailed error Trace:
{
"name": "AttributeError",
"message": "'TestCase' object has no attribute 'assertRaisesRegexp'",
"stack": "---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[29], line 3
2 from xyzClassifier.constants import *
----> 3 from xyzClassifier.utils.common import read_yaml, create_directories
5 import json
6 import joblib
----> 7 from ensure import ensure_annotations
8 from box import ConfigBox
9 from pathlib import Path
1 from __future__ import absolute_import, division, print_function, unicode_literals
3 from ._types import NumericString, NumericByteString, IntegerString, IntegerByteString
----> 4 from .main import EnsureError, Ensure, Check, ensure, check, ensure_raises, ensure_raises_regex, ensure_annotations
venv/lib/python3.12/site-packages/ensure/main.py:922
919 check = Check()
921 ensure_raises = unittest_case.assertRaises
--> 922 ensure_raises_regex = unittest_case.assertRaisesRegexp
AttributeError: 'TestCase' object has no attribute 'assertRaisesRegexp'"
}
Any help will be highly appreciated.
Upvotes: 0
Views: 57
Reputation: 3518
You may not be doing any unit testing yourself, but the ensure library is. It needs to be updated to version 1.0.4 in order to support Python 3.12.
Python 3 has long kept assertRaisesRegexp
(which was the name in Python 2) as an alias to assertRaisesRegex
, for backwards compatibility. In 3.12 it was finally removed, but prior versions of ensure were still using it.
Upvotes: 1