Skip to content

Commit

Permalink
feat(test): run tests with pytest 8.x and 7.x (#16)
Browse files Browse the repository at this point in the history
The [recently released `pytest` 8.0 brings some breaking changes,
deprecations, and new features. For future development, it'll be
nice to test the plugin with 7.x and 8.x versions
of `pytest` (while not many projects have been ported to 8.x ;-)

Here are the changes to the `hatch` configuration for this purpose…
  • Loading branch information
zaufi authored Feb 1, 2024
1 parent fd68e1c commit 0940841
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
- name: Run tests
run: |
hatch run test -v
hatch run run-tests
38 changes: 26 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ quiet-level = 3
skip = ".git,.venv,build,dist"

[tool.coverage.html]
directory = "build/coverage"
skip_empty = true
title = "Test Coverage Report"

Expand Down Expand Up @@ -92,11 +91,8 @@ tag-pattern = "release/(.*)"
description = "Development environment"
dependencies = [
"codespell >= 2.2.6"
, "coverage[toml]"
, "isort"
, "mypy"
, "pytest >= 7.0"
, "pytest-cov"
, "reuse"
, "ruff >= 0.1.14"
, "types-PyYAML"
Expand All @@ -119,15 +115,32 @@ pyproject-check = "validate-pyproject {root:real}/pyproject.toml"
spell-check = "codespell"
type-check = "mypy src/matcher test"
# Testing commands
coverage = "pytest --cov-report html --cov=matcher"
test = "pytest {verbosity:flag} {args}"
run-tests = "hatch env run -e test test"
# Misc commands
annotate-code = "reuse annotate -c \"$(git config --get user.name) <$(git config --get user.email)>\" -t code -l GPL-3.0-or-later {args}"
annotate-misc = "reuse annotate -c \"$(git config --get user.name) <$(git config --get user.email)>\" -t misc -l CC0-1.0 {args}"
dist = "hatch build -t wheel"
show-coverage = "xdg-open build/coverage/index.html"
fix-spelling = "codespell -i 3 -w"

[tool.hatch.envs.test]
description = "Unit tests environment"

[[tool.hatch.envs.test.matrix]]
pytest = ["pytest.8x", "pytest.7x"]

[tool.hatch.envs.test.overrides]
matrix.pytest.dependencies = [
"coverage[toml]"
, "pytest-cov"
, { value = "pytest ~= 8.0", if = ["pytest.8x"] }
, { value = "pytest ~= 7.0", if = ["pytest.7x"] }
]

[tool.hatch.envs.test.scripts]
cov = "pytest --cov-report term --cov-report html:build/coverage-{matrix:pytest} --cov=matcher"
show-cov = "xdg-open build/coverage-{matrix:pytest}/index.html"
test = "pytest -o cache_dir=build/.{matrix:pytest}_cache {verbosity:flag} {args}"

[tool.isort]
multi_line_output = 3
use_parentheses = true
Expand Down Expand Up @@ -169,14 +182,15 @@ notes = []

[tool.pytest.ini_options]
addopts = "-ra"
cache_dir = "build/.pytest_cache"
testpaths = ["test"]
python_files = ["test_*.py"]
python_classes = ["*Tester"]
python_functions = ["*_test", "*_test_?", "*_test_??"]
log_cli = true
markers = [
"wip: work in progress"
]
minversion = "7.0"
python_files = ["test_*.py"]
python_classes = ["*Tester"]
python_functions = ["*_test", "*_test_?", "*_test_??"]
testpaths = ["test"]

# https://beta.ruff.rs/docs/settings
[tool.ruff]
Expand Down

0 comments on commit 0940841

Please sign in to comment.