Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Test shows import error but project runs successfully via runserver

I have a django project with few apps. The project is running successfully without any error. Now I am writing test cases for some of the apps in the project.

I ran the test using following command

 python manage.py test apps.UserProfile
like image 888
Sudip Kafle Avatar asked Oct 26 '25 14:10

Sudip Kafle


1 Answers

You have a circular import. Your stack trace shows Student depends on Student through a bunch of other modules.

Usually you can solve this by changing your import statement to not have a "from"

Eg import apps.x.y.z

This form of import doesn't actually execute the imported module when it hits that statement, so it doesn't get stuck in a circular import loop.

like image 95
Nils Avatar answered Oct 28 '25 04:10

Nils



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!