-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v8.2.0 raises Can't instantiate abstract class
when a test class implements an abstract class
#12275
Comments
Can't instantiate abstract class
when test classes implements an abstract classCan't instantiate abstract class
when a test class implements an abstract class
Your suspicion is correct, a bisect indeed points to 1a5e0eb. |
Thanks for the report. I agree that what you're doing is very reasonable and should work. Until we have some fix for this, if you want to remove the pin, a workaround would be to drop this snippet to a conftest.py file in the directory where the abc is defined: import inspect
def pytest_pycollect_makeitem(collector, name, obj):
if inspect.isabstract(obj):
return [] |
Since I don't currently have time to attempt the change hinted at the final sentence in #12089, I suggest we just don't collect abstract classes for now. It probably makes some sense anyway -- the problem also exists for non-unittest test classes, so might as well fix it there as well. |
This will be fixed in pytest 8.3.0 (this fix is a bit too scary to backport to 8.2.x). |
* New json template * New JSON formatter * New JSON formatter * Use dict instead of list for other_info * Fix syntax * linter fixes * Fix tests * Fix variables * Try to force older pytest versions See pytest-dev/pytest#12275 * CentOS 7 is long gone * Fix the formatter
Before, we could have a test class inheriting from an ABC (and unittest.TestCase), now it errors because pytest is trying to instantiate the ABC itself. Running pytest should only instantiate the child test class (which indeed implements all the abstract methods of its ABC parent).
This issue does not appear in v8.1.2 and was likely introduced in #12089.
Minimal example:
Output:
pip list:
Thanks for your work in general, it's a great package.
The text was updated successfully, but these errors were encountered: