Skip to content

Commit e962ca6

Browse files
authored
Add pull request validation workflow (#1)
* Add workflow and replace pytest-cov with coverage package * Fix wrong group name in poetry install step * Update code coverage * Fix formatting issues, add badges and add trigger for main branch * Remove limitations on installed dependencies to fix type analysis * Fix template files matching test file pattern * Fix inconsistency in test runs when using tox vs. IDE Problem was caused by pytester reusing the terminal width of the pytest process resulting in inconsistent result for the summary block of the pytest output * Fix coverage calls and add development documentation * Add unit tests for get_parametrized_value * Add unit tests for get_parameter_from_type_hints * Formatting
1 parent 0281ab2 commit e962ca6

19 files changed

+409
-35
lines changed

.github/workflows/run-checks.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Run pull request validation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
run-checks:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
include:
17+
- python-version: "3.10"
18+
- python-version: "3.11"
19+
- python-version: "3.12"
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v5
25+
id: setup-python
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install poetry
30+
run: |
31+
python -m pip install poetry==1.8.2
32+
33+
- name: Configure poetry
34+
run: |
35+
python -m poetry config virtualenvs.in-project true
36+
37+
- name: Cache the virtualenv
38+
id: poetry-dependencies-cache
39+
uses: actions/cache@v3
40+
with:
41+
path: ./.venv
42+
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
43+
44+
- name: Install dev dependencies
45+
if: steps.poetry-dependencies-cache.outputs.cache-hit != 'true'
46+
run: |
47+
python -m poetry install
48+
49+
- name: Check for formatting issues
50+
run: python -m poetry run black --check --diff .
51+
52+
- name: Check for linting issues
53+
run: python -m poetry run ruff check .
54+
55+
- name: Run static type analysis
56+
run: python -m poetry run mypy .
57+
58+
- name: Test with tox
59+
run: |
60+
source .venv/bin/activate
61+
coverage erase
62+
tox run-parallel -f py${{ matrix.python-version }} --parallel-no-spinner --parallel-live
63+
coverage xml
64+
65+
- name: Upload coverage reports to Codecov
66+
uses: codecov/codecov-action@v4
67+
with:
68+
fail_ci_if_error: true
69+
token: ${{ secrets.CODECOV_TOKEN }}
70+
verbose: true

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ coverage.xml
7777

7878
# OS
7979
.DS_Store
80-
Thumbs.db
80+
Thumbs.db
81+
82+
# Coverage
83+
.coverage
84+
.coverage.*
85+
.cache

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Package to use type annotations for parametrization in pytest
22

3+
[![codecov](https://codecov.io/gh/skeletorXVI/pytest-parametrization-annotation/graph/badge.svg?token=22CXIHTW1Q)](https://codecov.io/gh/skeletorXVI/pytest-parametrization-annotation)
4+
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
5+
36
This package allows the declaration of parametrization using type annotations and definition of test cases using a
47
decorator.
58

@@ -108,3 +111,30 @@ from pytest_parametrization_annotation import Parametrized
108111
def test(a: Annotated[int, Parametrized]) -> None:
109112
...
110113
```
114+
115+
## Develop
116+
117+
### Install dependencies
118+
119+
```shell
120+
poetry install
121+
```
122+
123+
### Format code
124+
125+
```shell
126+
poetry run ruff format
127+
poetry run black .
128+
```
129+
130+
### Run static type checker
131+
132+
```shell
133+
poetry run mypy .
134+
```
135+
136+
### Run tests
137+
138+
```shell
139+
poetry run tox run-parallel
140+
```

examples/test_indirect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
@pytest.fixture
1313
def doubled(request: FixtureRequest) -> int:
14-
return request.param * 2
14+
value: int = request.param
15+
return value * 2
1516

1617

1718
@pytest.mark.case(

poetry.lock

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ black = "v24.3"
4444
mypy = "^1.9.0"
4545

4646
[tool.poetry.group.testing.dependencies]
47-
pytest-cov = "*"
4847
jinja2 = ">=3"
4948
tox = "^4.14.2"
49+
coverage = {extras = ["toml"], version = ">=6.5.0"}
5050

5151
[build-system]
5252
requires = ["poetry-core"]
@@ -71,4 +71,9 @@ target-version = ["py310", "py311", "py312"]
7171
python_version = "3.10"
7272
warn_return_any = true
7373
warn_unused_configs = true
74-
files = ["src", "tests"]
74+
files = ["src", "tests"]
75+
76+
[tool.coverage.report]
77+
exclude_lines = [
78+
"if TYPE_CHECKING:"
79+
]

src/pytest_parametrization_annotation/annotation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
class Parametrized:
1010
indirect: bool = False
1111
default: Any = _Default
12-
default_factory: Callable[[], Any] = _DefaultCallable
12+
default_factory: Callable[[], Any] = _DefaultCallable

src/pytest_parametrization_annotation/functionality.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from __future__ import annotations
22

3-
from typing import Annotated, Any, Callable, Mapping, get_origin, get_type_hints, TYPE_CHECKING
3+
from typing import (
4+
Annotated,
5+
Any,
6+
Callable,
7+
Mapping,
8+
get_origin,
9+
get_type_hints,
10+
TYPE_CHECKING,
11+
)
412

513
from _pytest.outcomes import fail
614

@@ -37,7 +45,7 @@ def get_parameters_from_type_hints(func: Callable) -> dict[str, Parametrized]:
3745

3846

3947
def get_parametrized_value(
40-
kwargs: Mapping[str, Any], parameter: str, meta: Parametrized
48+
kwargs: Mapping[str, Any], parameter: str, meta: Parametrized
4149
) -> Any:
4250
if parameter in kwargs:
4351
return kwargs[parameter]

src/pytest_parametrization_annotation/plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
def pytest_configure(config: Config) -> None:
12-
config.addinivalue_line("markers", "case: Parametrize the test with the provided values.")
12+
config.addinivalue_line(
13+
"markers", "case: Parametrize the test with the provided values."
14+
)
1315

1416

1517
def pytest_generate_tests(metafunc: Metafunc) -> None:

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pytest_plugins = ["pytester"]
1+
pytest_plugins = ["pytester"]

0 commit comments

Comments
 (0)