TypeError: issubclass() arg 1 must be a class in Django tests

I am using Django 2.1.5 and pycharm. When running tests from Pycharm I started getting this error:

File "/Users/..../lib/python3.6/site-packages/nose/loader.py", line 576, in _makeTest
if issubclass(parent, unittest.TestCase):

TypeError: issubclass() arg 1 must be a class

I’m getting it only when trying to run one test (and not a test class). Also getting it when trying to run it through

python manage.py test specific_test

I understand the error meaning, but I don’t understand why I started getting it suddenly.

EDIT:

Full traceback:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/..../lib/python3.6/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
File "/..../lib/python3.6/site- 
packages/nose/loader.py", line 523, in makeTest
return self._makeTest(obj, parent)
File "/..../lib/python3.6/site-packages/nose/loader.py", line 576, in _makeTest
if issubclass(parent, unittest.TestCase):
TypeError: issubclass() arg 1 must be a class

the parent is

<function MyTestClass.test_function at 0x10ff32f28>

Answer

I get this error when I don’t properly point to the test I’m trying to run.

When I tried to run a specific test method I tried the following and got the error you mention: ./manage.py test myapp.tests.test_file.MyTestCase.test_something

What I had to run to actually get it to work was: ./manage.py test myapp.tests.test_file:MyTestCase.test_something (Notice the : between the file name and the class name)

I believe this issue is specific to ‘nose’.

Leave a Reply

Your email address will not be published. Required fields are marked *