cookiecutter-django icon indicating copy to clipboard operation
cookiecutter-django copied to clipboard

Docker + Pycharm Test Problem

Open charleshan opened this issue 4 years ago • 5 comments

  1. docker-compose -f local.yml run django python manage.py test works fine
  2. Using Docker Python Interpreter in PyCharm to run the tests throws an error:
psycopg2.OperationalError: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  1. Tests run correctly when Docker-compose is used in Pycharm but it exits the existing container.

It could be that we just need better documentation on how to use Cookiecutter + Docker + Pycharm but I couldn't get either of the last two methods to work correctly.

charleshan avatar Mar 17 '20 19:03 charleshan

When you press run, PyCharm prints the command. What was the command? Additionally, did you first build then migrate THEN run the tests? Lastly, UNIX domain on Windows... are you using a Linux subsystem on a Windows machine?

Andrew-Chen-Wang avatar Mar 18 '20 04:03 Andrew-Chen-Wang

When you press run, PyCharm prints the command. What was the command?

python -u /opt/.pycharm_helpers/pycharm/django_test_manage.py test myproject.tests.TestMyProjectView /opt/project

did you first build then migrate THEN run the tests?

docker-compose should do this. As I mentioned on 3, it runs fine when running from the terminal.

Lastly, UNIX domain on Windows... are you using a Linux subsystem on a Windows machine?

I'm on Mac OS X.

charleshan avatar Mar 19 '20 23:03 charleshan

I just tried and was unable to reproduce the problem. Here is what I did:

  1. I created a project using Docker + Pycharm
  2. Opened project in PyCharm
  3. Configured a remote interpreter with Docker Compose:
    • config file: local.yml
    • service: django
    • left all the rest as default
  4. Wait a couple of minute for PyCharm to connect & save
  5. Run pytest configuration on the top right, all good

Can you clarify what you mean by "Using Docker Python Interpreter in PyCharm to run the tests"? I have a different command printed at step 4, so I

The error you get seems to indicate that the DB isn't able to start or bind the port properly. If you open the "Services" tool window (⌘ + 8), is posgres running in your compose stack? You can click on it to see the logs.

Do you have Postgres installed on your Mac? I had issues in the past where Docker was trying to bind the same port as the server running on my host machine.

browniebroke avatar Mar 20 '20 12:03 browniebroke

@browniebroke those are the exact steps I took for 3)

By Docker Python Interpreter in PyCharm in 2), I meant using a remote interpreter with Docker.

I do have Postgres installed on my Mac but I run into a different problem when I use a remote interpreter with Docker Compose. The tests run fine but it exits the existing container.

charleshan avatar Mar 21 '20 02:03 charleshan

I had all sorts of problems with postgres because I forgot to delete volumes. If I have a postgres problem in dev the first thing i do is delete unused volumes

periwinkleFTW avatar Jan 07 '21 11:01 periwinkleFTW

Closing this as I'm still unable to reproduce.

browniebroke avatar Jan 31 '23 23:01 browniebroke