Help running tests using docker-compose and pytest
Answered
Hello,
I'm having trouble setting up what should be a simple environment for my tests. I've got pytest set as my default test runner and have a working docker-compose config that I can successfully start up and run for development. I can't seem to get a proper pytest config running though and think it's just a lack of knowledge on my part.
I've attached a screenshots of the error I'm getting trying to run said test. Note running them locally outside of PyCharm and outside of Docker succeeds.
Any advice is greatly appreciated.



Please sign in to leave a comment.
Hi,
Does it happen with that particular test? Can you reproduce it in a new test project?
Please also let me know your PyCharm version.
Hi Sergey,
Thanks for getting back to me. It currently happens with any test in my project. My project is pretty young is this is my initial attempt to get things up and running through PyCharm rather than through the terminal so I'd say yes to your question about being able to reproduce it.
PyCharm: 2019.2
Thanks!
Could you please configure another docker-compose based interpreter following our documentation and see how it goes? https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html
If it works fine, then it's related to your configs I guess.
I've already gone through those instructions. The end result of everything combined is what you see in the images I posted. I think this is a simple matter of not setting up the run config properly. I just don't have the experience to know what it is I'm missing as I can't seem to find any documentation that gives good examples of test configs when running inside Docker and Docker-Compose.
The easiest way run your files is to right-click it and choose Run...
PyCharm will create run/debug configuration automatically. Though looking at your screenshot it seems to be correct already.
Is it possible to share that project or its relevant part so I can check it on my side? You can upload it to https://uploads.services.jetbrains.com/ but please let me know the name of the file so I can find it on the server.
"The easiest way run your files is to right-click it and choose Run..."
Yes but it will be ru unitest not pytest.
I use pytest.ini
and put there
@Ruslan Skira
What test runner do you have selected in Settings/Preferences | Tools | Python Integrated Tools?
It looks like this thread has gone stale, but I’ve had the same issue. With a docker compose interpreter, pycharm uses the unittest runner instead of pytest runner, even with pytest runner explicitly selected in settings.