From f890cdba23d1158499649a20a071413db68d031e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 14:53:50 +0100 Subject: [PATCH 1/7] Refactor runtests.sh --- tests/requirements.txt | 2 ++ tests/runtests.sh | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/requirements.txt diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..b420b44 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,2 @@ +# test requirements +pytest diff --git a/tests/runtests.sh b/tests/runtests.sh index b1f9a36..cf605df 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -6,8 +6,9 @@ set -e # which is assumed to be mounted somewhere in the docker image. here=$(dirname $0) -testvenv=/tmp/testvenv +testvenv=/tmp/testvenv /usr/bin/python3 -m venv $testvenv -$testvenv/bin/pip install pytest +$testvenv/bin/pip install -r $here/requirements.txt + $testvenv/bin/pytest --color=yes --ignore $here/data $here "$@" From b00fb9afb9d9efcc9190db0a3e8546f8b0de2cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 14:54:20 +0100 Subject: [PATCH 2/7] Mount whole project in test container --- tests/docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index e66d387..6fc51f5 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -7,8 +7,8 @@ services: python_version: "3.10" odoo_version: "16.0" volumes: - - .:/mnt/tests - working_dir: /mnt/tests + - ..:/mnt/oca-ci + working_dir: /mnt/oca-ci/tests depends_on: - postgres postgres: @@ -16,4 +16,4 @@ services: environment: POSTGRES_USER: odoo POSTGRES_PASSWORD: odoo - POSTGRES_DB: odoo \ No newline at end of file + POSTGRES_DB: odoo From c2782e54dbbd3500e1c21001a6cd752c277a2398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 14:55:02 +0100 Subject: [PATCH 3/7] Add bin to runtest.sh PATH This is less surprising when iterating on the scripts --- tests/runtests.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/runtests.sh b/tests/runtests.sh index cf605df..3fcee4c 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -11,4 +11,6 @@ testvenv=/tmp/testvenv /usr/bin/python3 -m venv $testvenv $testvenv/bin/pip install -r $here/requirements.txt +export PATH=$here/../bin:$PATH + $testvenv/bin/pytest --color=yes --ignore $here/data $here "$@" From f8ca2bb19bff578d2aef57aa6c49a4dadb23833f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 14:55:52 +0100 Subject: [PATCH 4/7] Add devcontainer config --- .devcontainer/devcontainer.json | 45 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 3 +++ 2 files changed, 48 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3eddf83 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,45 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose +{ + "name": "Existing Docker Compose (Extend)", + + // Update the 'dockerComposeFile' list if you have more compose files or use different names. + // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make. + "dockerComposeFile": [ + "../tests/docker-compose.yml", + "docker-compose.yml", + ], + + // The 'service' property is the name of the service for the container that VS Code should + // use. Update this value and .devcontainer/docker-compose.yml to the real service name. + "service": "test", + + // The optional 'workspaceFolder' property is the path VS Code should open by default when + // connected. This is typically a file mount in .devcontainer/docker-compose.yml + "workspaceFolder": "/mnt/oca-ci", + + "remoteEnv": { + "PATH": "/mnt/oca-ci/bin:${containerEnv:PATH}", + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..c8485f3 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,3 @@ +services: + test: + command: [sleep, infinity] From 76932a30882dc3e93772a22167b1cb56f7ff9e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 14:55:59 +0100 Subject: [PATCH 5/7] Add pytest configuration --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..6367d37 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +testpaths = + tests +addopts = --ignore=tests/data From ab013b60b8e3434602df991bb751e7921ce3f78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 15:14:04 +0100 Subject: [PATCH 6/7] Improve test instructions in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fc65adb..7a58adb 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,7 @@ Tune it to your liking, then run: `docker compose run --build test ./runtests.sh -v` +This docker-compose mounts this project, and `runtests.sh` adds then `bin` directory to +the `PATH` for easier dev/test iteration. + +There is also a devcontainer configuration. From 1c97f1356ae1f83e89f614aade127f833d51326e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 17 Mar 2024 15:32:18 +0100 Subject: [PATCH 7/7] Set default image in test docker-compose For faster startup --- tests/docker-compose.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 6fc51f5..8128ad8 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -1,11 +1,12 @@ services: test: - build: - context: .. - args: - codename: jammy - python_version: "3.10" - odoo_version: "16.0" + image: ghcr.io/oca/oca-ci/py3.10-ocb16.0:latest + # build: + # context: .. + # args: + # codename: jammy + # python_version: "3.10" + # odoo_version: "16.0" volumes: - ..:/mnt/oca-ci working_dir: /mnt/oca-ci/tests