diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a2aff36dc6..2cdb8cf1fe 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -19,13 +19,13 @@ jobs: - uses: actions/checkout@v3 - name: Install poetry run: | - python -m pip install --upgrade pip - pipx install poetry + python -m pip install --upgrade pip + pipx install poetry - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - cache: 'poetry' + cache: "poetry" - name: Install dependencies run: | poetry install @@ -61,4 +61,8 @@ jobs: /tmp/hadolint Dockerfile --ignore=DL3013 - name: Test with pytest run: | - poetry run pytest tests -n auto + poetry run pytest -n auto --cov=./prowler --cov-report=xml tests + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 15936b9bef..080f175803 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,7 @@ junit-reports/ # .env .env* + +# Coverage +.coverage* +coverage* diff --git a/Makefile b/Makefile index 81853634cb..227f4073d7 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,20 @@ ##@ Testing test: ## Test with pytest - pytest -n auto -vvv -s -x + pytest -n auto -vvv -s -x + rm -rf .coverage && \ + rm -rf ./htmlcov && \ + pytest -n auto --cov=./prowler --cov-report=xml tests coverage: ## Show Test Coverage - coverage run --skip-covered -m pytest -v && \ - coverage report -m && \ - rm -rf .coverage + coverage run --skip-covered -m pytest -v && \ + coverage report -m && \ + rm -rf .coverage + coverage report -m + +coverage-html: ## Show Test Coverage + coverage html && \ + open htmlcov/index.html ##@ Linting format: ## Format Code diff --git a/poetry.lock b/poetry.lock index 1689cd9644..639f377c42 100644 --- a/poetry.lock +++ b/poetry.lock @@ -636,6 +636,9 @@ files = [ {file = "coverage-7.2.7.tar.gz", hash = "sha256:924d94291ca674905fe9481f12294eb11f2d3d3fd1adb20314ba89e94f44ed59"}, ] +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + [package.extras] toml = ["tomli"] @@ -1912,6 +1915,24 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-cov" +version = "4.1.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-cov-4.1.0.tar.gz", hash = "sha256:3904b13dfbfec47f003b8e77fd5b589cd11904a21ddf1ab38a64f204d6a10ef6"}, + {file = "pytest_cov-4.1.0-py3-none-any.whl", hash = "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a"}, +] + +[package.dependencies] +coverage = {version = ">=5.2.1", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] + [[package]] name = "pytest-randomly" version = "3.13.0" @@ -2895,4 +2916,4 @@ docs = ["mkdocs", "mkdocs-material"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "17459c4c8a7acf4c4a31253edf406113fbcedf8d81d17042f6b33665c3a6f47d" +content-hash = "7e241e96b044edcc8097879cea3219952a8344cd08ab3ede8d88bdb98d3a560a" diff --git a/pyproject.toml b/pyproject.toml index c2acbd4dd1..8cbea90893 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,7 @@ moto = "4.1.14" openapi-spec-validator = "0.6.0" pylint = "2.17.5" pytest = "7.4.0" +pytest-cov = "4.1.0" pytest-randomly = "3.13.0" pytest-xdist = "3.3.1" safety = "2.3.5"