diff --git a/.github/workflows/check_n_push_image.yml b/.github/workflows/check_n_push_image.yml index 79321213..d4c5b203 100644 --- a/.github/workflows/check_n_push_image.yml +++ b/.github/workflows/check_n_push_image.yml @@ -64,6 +64,11 @@ jobs: make docker-image DOCKER_TAG=${{ secrets.DOCKER_HUB_USERNAME }}/codeplag-ubuntu22.04:${{ steps.get_version.outputs.version }} docker image save --output /tmp/codeplag-ubuntu22.04.tar ${{ secrets.DOCKER_HUB_USERNAME }}/codeplag-ubuntu22.04:${{ steps.get_version.outputs.version }} + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@v1 + with: + pytest-xml-coverage-path: ./test/unit/pytest-coverage.xml + - name: Run autotests run: | export $(cat .env | xargs) diff --git a/.gitignore b/.gitignore index 8fd9b666..677be114 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,11 @@ # Environment variables .env -# Developmnt environmemt +# Development and environment .vscode .python-version docs/notebooks/.ipynb_checkpoints/ +test/unit/pytest-coverage.xml # Build __pycache__ diff --git a/Makefile b/Makefile index affecc71..ba147a1e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -UTIL_VERSION := 0.5.14 +UTIL_VERSION := 0.5.15 UTIL_NAME := codeplag PWD := $(shell pwd) @@ -33,6 +33,7 @@ DOCKER_SUB_FILES := docker/base_ubuntu2204.dockerfile \ PYTHON_REQUIRED_LIBS := $(shell python3 setup.py --install-requirements) PYTHON_BUILD_LIBS := $(shell python3 setup.py --build-requirements) +PYTHON_TEST_LIBS := $(shell python3 setup.py --test-requirements) ifeq ($(IS_DEVELOPED), 1) @@ -49,6 +50,7 @@ substitute = @sed \ -e "s|@DEVEL_SUFFIX@|${DEVEL_SUFFIX}|g" \ -e "s|@PYTHON_REQUIRED_LIBS@|${PYTHON_REQUIRED_LIBS}|g" \ -e "s|@PYTHON_BUILD_LIBS@|${PYTHON_BUILD_LIBS}|g" \ + -e "s|@PYTHON_TEST_LIBS@|${PYTHON_TEST_LIBS}|g" \ -e "s|@LOGS_PATH@|${LOGS_PATH}|g" \ -e "s|@LIB_PATH@|${LIB_PATH}|g" \ -e "s|@CONFIG_PATH@|${CONFIG_PATH}|g" \ @@ -127,12 +129,11 @@ package: substitute-debian ) test: substitute-sources - pytest test/unit -vv - pytest test/misc -vv + pytest test/unit test/misc --cov=src/ --cov-report xml --cov-report term make clean-cache autotest: - pytest test/auto -vv + pytest test/auto make clean-cache pre-commit: diff --git a/README.md b/README.md index 37d73dd1..703655e4 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ - Testing for analyzers with pytest lib (required preinstalled pytest framework). ``` - $ pip3 install pytest==8.3.4 pytest-mock==3.14.0 + $ pip3 install $(python3 setup.py --test-requirements) $ make test ``` diff --git a/docker/test_ubuntu2204.dockerfile.in b/docker/test_ubuntu2204.dockerfile.in index acda41c5..38f3c29b 100644 --- a/docker/test_ubuntu2204.dockerfile.in +++ b/docker/test_ubuntu2204.dockerfile.in @@ -4,11 +4,12 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update RUN apt-get install -y debhelper -RUN pip3 install pytest==8.3.4 pytest-mock==3.14.0 @PYTHON_BUILD_LIBS@ +RUN pip3 install @PYTHON_TEST_LIBS@ @PYTHON_BUILD_LIBS@ RUN mkdir -p @LOGS_PATH@ # TODO: Move to middle docker file or make another solution ADD setup.py /usr/src/@UTIL_NAME@/setup.py +ADD pyproject.toml /usr/src/@UTIL_NAME@/pyproject.toml ADD src/ /usr/src/@UTIL_NAME@/src ADD README.md /usr/src/@UTIL_NAME@/README.md ADD LICENSE /usr/src/@UTIL_NAME@/LICENSE diff --git a/pyproject.toml b/pyproject.toml index 086fa352..53f5f81c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,3 +59,22 @@ typeCheckingMode = "basic" [build-system] requires = ["setuptools", "Cython"] + +[tool.coverage.run] +branch = true + +[tool.coverage.report] +include_namespace_packages = true +precision = 2 + +[tool.coverage.xml] +output = "test/unit/pytest-coverage.xml" + +[tool.pytest.ini_options] +addopts = "-vv" +python_files = ["test_*.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] +pythonpath = [ + "src", +] diff --git a/setup.py b/setup.py index ef763736..eef2bf51 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,11 @@ "setuptools~=75.8.1", "Jinja2~=3.1.5", ) +TEST_REQUIREMENTS: tuple[str, ...] = ( + "pytest~=8.3.4", + "pytest-mock~=3.14.0", + "pytest-cov~=6.0.0", +) INSTALL_REQUIREMENTS: tuple[str, ...] = ( "argcomplete~=3.5.3", "numpy~=1.26.4", @@ -32,6 +37,9 @@ if "--build-requirements" in sys.argv: print(" ".join(BUILD_REQUIREMENTS)) sys.exit(0) +if "--test-requirements" in sys.argv: + print(" ".join(TEST_REQUIREMENTS)) + sys.exit(0) elif "--install-requirements" in sys.argv: print(" ".join(INSTALL_REQUIREMENTS)) sys.exit(0)