Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm throws "AttributeError: 'module' object has no attribute" when running tests for no reason

So, I have a Django-REST Framework project and one day it simply ceased being able to run the tests within PyCharm.

From the command line I can run them both using paver or the manage.py directly.

There was a time when that would happen when we didn't import the class' superclass at the top of the file, but that's not the case.

We have a virtualenv set locally and run the server from a vagrant box. I assured the virtual environment is loaded and that the project's Interpreter is using the afore mentioned virtual env.

No clue on what's the matter.

like image 300
Alvaro Cavalcanti Avatar asked Oct 19 '22 02:10

Alvaro Cavalcanti


2 Answers

I had the same problem but my solution was different.

When I tried to run a test from PyCharm, the target path looked like this:

  • tests.apps.an_app.models.a_model.ATestCase

But since ATest was a class inside a_model.py, the targ path should actually be:

  • tests.apps.an_app.models.a_model:ATestCase

Changing the target in the test configuration worked.

like image 177
ariannedee Avatar answered Oct 21 '22 17:10

ariannedee


Given all the others paths were already covered:

  • Import order
  • Virtual Env created
  • Project's Interpreter using the Virtual Env

The only thing that occurred to me was do run the following command within the vurtal env:

pip install -r requirements.txt

And it worked! In the end, someone had updated the requirements which weren't being met by my current virtual env. Screwing up with the paths/imports within PyCharm.

like image 43
Alvaro Cavalcanti Avatar answered Oct 21 '22 15:10

Alvaro Cavalcanti