[Fixed]-Django test error only with pycharm – Not the terminal | apps aren't loaded yet

3👍

This seems like a Virtual Environment loading error. Have you applied the correct Virtual Environment to your testing env? Check this article and try running it again. http://exponential.io/blog/2015/02/10/configure-pycharm-to-use-virtualenv/

Also on another note, if you’re testig for correct template loading or GET requests feel free look at my tutorial.

👤IVI

1👍

Do you have the correct “Working directory” values and “Target” for your tests?

I faced similar issues with Behave tests…

👤Edwin

1👍

This worked for me:

  1. Run the test (it fails with the error)

  2. Click the dropdown next to the test name and select ‘Edit configurations’

  3. Click on the test name in the left hand panel of the ‘Run/Debug configurations’
    dialog.

  4. Click the minus sign to delete the test. Click OK

  5. Now re-run the test and it passes for me.

My hunch is that dodgy test config gets cached under .idea/ and explicitly deleting the test removes or updates it.

Another workaround is to manually create a Django test:

  1. Edit Configurations

  2. Add new configuration (click the ‘+’ button)

  3. Select ‘Django Tests’

  4. Under ‘Target’, enter the path to the test module (e.g. ‘your_app.your_module.tests’)

  5. Click OK, and you should be able to run this configuration.

Leave a comment