camptocamp / pytest-odoo

pytest plugin to run Odoo tests
GNU Affero General Public License v3.0
67 stars 41 forks source link

How to use pytest when Odoo is running from docker container ? #39

Open tarekmokhtarjr opened 3 years ago

tarekmokhtarjr commented 3 years ago

Hello guys,

first i would like to thank you for this awesome tool ! I'm running Odoo from docker container and what i did is the following :

  1. I got inside the container using this command docker exec -ti <my_odoo_container> bash
  2. Then i installed pytest-odoo inside the container pip3 install pytest-odoo
  3. I used this command to run the test pytest -s addons/<my_module>/tests/test_account_move.py --odoo-database=staging_3

But it gives me this error OSError: [Errno 98] Address already in use : image

Did anyone encounter a similar issue ?

Thanks.

yvaucher commented 3 years ago

Hello @tarek-caesar

Instead of using an existing container, you might prefer to create a new container just to run pytest if you need your server online at the same time. Note that to run the tests you usually want to generate a new database in demo data mode.

If you use the docker-odoo-project image you can use the tools testdb-gen and testdb-update for this before launching pytest.

https://github.com/camptocamp/docker-odoo-project#pytests

tarekmokhtarjr commented 3 years ago

@yvaucher

Thanks for your answer, i will check that.

julia-suarez-deel commented 3 years ago

Hello I figured this out, I wrote an article to explain better how to run odoo's tests with pycharm, generate coverage reports and get debugging working, I hope this is useful for you: https://medium.com/plusteam/how-to-run-odoo-tests-with-pycharm-51e4823bdc59.

I included an example repository with some commands to set up a testing database, etc.

julia-suarez-deel commented 3 years ago

@tarek-caesar btw, you can run the tests in the same container you regularly use, you just need to specify a different port, like this:

pytest -s addons/<my_module>/tests/test_account_move.py --odoo-database=staging_3 -p 8001

The-macharia commented 2 years ago

You can use the param --no-http to run another instance without stopping odoo or exposing new ports