Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ on:
branches: ["main"]

jobs:
build:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
pytest-version: ["5.*", "6.*", "7.*", "8.*", "9.*"]
exclude:
- python-version: "3.9"
pytest-version: "9.*"

steps:
- uses: actions/checkout@v3
Expand All @@ -23,13 +27,28 @@ jobs:
version: "latest"
- name: Install Python and dependencies
run: uv sync --python-preference=only-managed --python=${{ matrix.python-version }}
- name: Install specific pytest version
run: uv pip install pytest==${{ matrix.pytest-version }}
- name: Test
run: |
uv run --frozen coverage run -m pytest
uv run --frozen coverage report

verify:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
version: "latest"
- name: Install Python and dependencies
run: uv sync --python-preference=only-managed --python=3.14
- name: Lint
run: uv run --frozen ruff check --output-format=github
- name: Format
run: uv run --frozen ruff format --diff
- name: Type Check
run: uv run --frozen ty check --output-format=github
run: uv run --frozen ty check --output-format=github
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
readme = "README.md"
license = { file = "LICENSE.md" }
requires-python = ">=3.9"
dependencies = ["pytest>=8.1.1"]
dependencies = ["pytest>=5.0.0"]

[dependency-groups]
dev = [
Expand All @@ -40,7 +40,7 @@ Changelog = "https://github.com/NiclasvanEyk/pytest-gitlab-code-quality/blob/mai
Funding = "https://github.com/sponsors/NiclasvanEyk"

[project.entry-points.pytest11]
pytest-gitlab-code-quality = "pytest_gitlab_code_quality"
pytest-gitlab-code-quality = "pytest_gitlab_code_quality.pytest_hooks"

[build-system]
requires = ["hatchling"]
Expand Down
29 changes: 1 addition & 28 deletions src/pytest_gitlab_code_quality/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
from pathlib import Path

from pytest import Config, Parser, PytestPluginManager

from pytest_gitlab_code_quality.plugin import GitlabCodeQualityReportPlugin
from pytest_gitlab_code_quality.recorder import ViolationRecorder


def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None:
parser.addoption(
"--gitlab-code-quality-report",
default="pytest-warnings.json",
required=False,
help="Outputs warnings in GitLabs Code Quality Report file.",
)


def pytest_configure(config: Config) -> None:
report_path = config.getoption("gitlab_code_quality_report")
if report_path is None:
return

file = Path(str(report_path)).open("w") # noqa: SIM115
recorder = ViolationRecorder(file)
recorder.prepare()
plugin = GitlabCodeQualityReportPlugin(recorder, config.rootpath)

_ = config.pluginmanager.register(plugin, "gitlab_code_quality")
"""Collects warnings while testing and generates a GitLab Code Quality Report."""
28 changes: 28 additions & 0 deletions src/pytest_gitlab_code_quality/pytest_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path

from pytest import Config, Parser, PytestPluginManager

from pytest_gitlab_code_quality.plugin import GitlabCodeQualityReportPlugin
from pytest_gitlab_code_quality.recorder import ViolationRecorder


def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None:
parser.addoption(
"--gitlab-code-quality-report",
default="pytest-warnings.json",
required=False,
help="Outputs warnings in GitLabs Code Quality Report file.",
)


def pytest_configure(config: Config) -> None:
report_path = config.getoption("gitlab_code_quality_report")
if report_path is None:
return

file = Path(str(report_path)).open("w") # noqa: SIM115 - file is kept open for streaming, closed via pytest_unconfigure
recorder = ViolationRecorder(file)
recorder.prepare()
plugin = GitlabCodeQualityReportPlugin(recorder, config.rootpath)

_ = config.pluginmanager.register(plugin, "gitlab_code_quality")
Loading
Loading