diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a86e70bd8..bc8bc3875 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,7 @@ name: test CI on: [pull_request] jobs: + pytest_with_coverage: runs-on: ubuntu-20.04 timeout-minutes: 20 @@ -13,13 +14,20 @@ jobs: run: | docker-compose -f docker/docker-compose_tests.yml build - name: Execute pytest with coverage trace under ota-test_base container + # NOTE: test_result folder holds the coverage.xml, check docker-compose_tests.yml for + # coverage execution command line and volumes configurations. run: | set -o pipefail - docker-compose -f docker/docker-compose_tests.yml up --no-log-prefix --abort-on-container-exit | tee pytest-coverage.txt + mkdir test_result + docker-compose -f docker/docker-compose_tests.yml up --no-log-prefix --abort-on-container-exit # export the coverage report to the comment! - name: Add coverage report to PR comment continue-on-error: true - uses: MishaKav/pytest-coverage-comment@v1.1.40 + uses: MishaKav/pytest-coverage-comment@v1.1.49 + with: + pytest-xml-coverage-path: test_result/coverage.xml + junitxml-path: test_result/pytest.xml + python_lint_check: runs-on: ubuntu-20.04 timeout-minutes: 3 diff --git a/docker/docker-compose_tests.yml b/docker/docker-compose_tests.yml index 0c5ff3f61..800ab730f 100644 --- a/docker/docker-compose_tests.yml +++ b/docker/docker-compose_tests.yml @@ -6,10 +6,11 @@ services: dockerfile: ./docker/test_base/Dockerfile image: ota-test_base network_mode: bridge - command: "python3 -m pytest" + command: "bash -c 'coverage run -m pytest --junit-xml=test_result/pytest.xml && coverage xml -o test_result/coverage.xml'" container_name: ota-test volumes: - ../pyproject.toml:/ota-client/pyproject.toml:ro - ../.flake8:/ota-client/.flake8:ro - ../otaclient:/ota-client/otaclient:ro - ../tests:/ota-client/tests:ro + - ../test_result:/ota-client/test_result:rw diff --git a/pyproject.toml b/pyproject.toml index 1d307a7cf..9e1ce3843 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,10 +41,21 @@ extend-exclude = '''( [tool.coverage.run] branch = false +omit = ["**/*_pb2.py*","**/*_pb2_grpc.py*"] +source = ["otaclient.app", "otaclient.ota_proxy"] [tool.coverage.report] -omit = ["**/*_pb2.py*","**/*_pb2_grpc.py*"] +exclude_also = [ + "def __repr__", + "if cfg.DEBUG_MODE", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", + "class .*\\bProtocol\\):", + "@(abc\\.)?abstractmethod", + ] show_missing = true +skip_covered = true +skip_empty = true [tool.pyright] exclude = ["**/__pycache__"] @@ -52,7 +63,6 @@ ignore = ["**/*_pb2.py*","**/*_pb2_grpc.py*"] pythonVersion = "3.8" [tool.pytest.ini_options] -addopts = "--cov=otaclient.app --cov=otaclient.ota_proxy" asyncio_mode = "auto" log_auto_indent = true log_format = "%(asctime)s %(levelname)s %(filename)s %(funcName)s,%(lineno)d %(message)s" diff --git a/tests/requirements.txt b/tests/requirements.txt index ab1a57093..5f57f8749 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,7 +1,7 @@ pytest==7.1.2 pytest-asyncio==0.21.0 pytest-mock==3.8.2 -pytest-cov==3.0.0 +coverage==7.2.5 black==22.3.0 flake8==4.0.1 requests-mock==1.10.0