Skip to content

Commit d05b89f

Browse files
authored
test for pytest8 and python 3.12 (#13)
* test for pytest8 and python 3.12 * move to pyproject.toml
1 parent f8c309a commit d05b89f

File tree

10 files changed

+88
-172
lines changed

10 files changed

+88
-172
lines changed

.github/workflows/release.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ jobs:
1010
id-token: write
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- name: Set up Python 3.10
15-
uses: actions/setup-python@v4
13+
- uses: actions/checkout@v4
14+
- uses: wntrblm/[email protected]
1615
with:
17-
python-version: '3.10'
18-
- run: pip install -U nox
16+
python-versions: "3.12"
1917
- run: nox -s build
2018
- uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/tests.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3
8-
- uses: actions/setup-python@v4
8+
- uses: wntrblm/[email protected]
99
with:
10-
python-version: |
11-
3.8
12-
3.9
13-
3.10
14-
3.11
15-
pypy3.8
16-
pypy3.9
17-
3.7
18-
- run: pip install -U nox
10+
python-versions: "3.7, 3.8, 3.9, 3.10, 3.11, 3.12"
1911
- run: nox
2012
- run: nox -s build

.pre-commit-config.yaml

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
repos:
2-
- hooks:
3-
- id: black
4-
language_version: python3
5-
repo: https://github.com/psf/black
6-
rev: 22.6.0
72
- repo: https://github.com/pre-commit/pre-commit-hooks
83
rev: v4.3.0
94
hooks:
105
- id: check-toml
116
- id: check-yaml
127
- id: end-of-file-fixer
138
- id: trailing-whitespace
14-
- hooks:
9+
- repo: https://github.com/tox-dev/pyproject-fmt
10+
rev: "1.7.0"
11+
hooks:
12+
- id: pyproject-fmt
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.2.0
15+
hooks:
16+
- id: ruff
17+
args: [--fix, --exit-non-zero-on-fix]
18+
- id: ruff-format
19+
- repo: https://github.com/codespell-project/codespell
20+
rev: v2.2.2
21+
hooks:
1522
- id: codespell
1623
additional_dependencies: ["tomli"]
17-
repo: https://github.com/codespell-project/codespell
18-
rev: v2.2.2
19-
- hooks:
20-
- id: isort
21-
language_version: python3
22-
repo: https://github.com/timothycrosley/isort
23-
rev: 5.10.1
24-
- hooks:
25-
- id: flake8
26-
language_version: python3
27-
additional_dependencies:
28-
- flake8-bugbear
29-
- flake8-comprehensions
30-
- flake8-debugger
31-
- flake8-string-format
32-
- flake8-bandit
33-
repo: https://github.com/PyCQA/flake8
34-
rev: 5.0.4

noxfile.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
"""Automation using nox.
2-
"""
1+
"""Automation using nox."""
2+
33
import glob
4-
import sys
54

65
import nox
76

87
nox.options.reuse_existing_virtualenvs = True
9-
nox.options.sessions = "lint", "tests", "compat"
8+
nox.options.sessions = "lint", "tests"
109
locations = "pytest_test_utils", "tests.py"
1110

1211

13-
@nox.session(
14-
python=["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.8", "pypy3.9"]
15-
)
12+
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
1613
def tests(session: nox.Session) -> None:
1714
session.install(".[tests]")
1815
# `pytest --cov` will start coverage after pytest
@@ -21,29 +18,18 @@ def tests(session: nox.Session) -> None:
2118
session.run("coverage", "report", "--show-missing", "--skip-covered")
2219

2320

24-
@nox.session(python=["3.7", "3.8"])
25-
@nox.parametrize("pytest", ["3.9.1", "4.0", "5.0", "6.0"])
26-
def compat(session: nox.Session, pytest: str) -> None:
27-
session.install(".[tests]")
28-
session.install(f"pytest=={pytest}")
29-
session.run("coverage", "run", "-m", "pytest", "tests.py")
30-
31-
3221
@nox.session
3322
def lint(session: nox.Session) -> None:
3423
session.install("pre-commit")
3524
session.install("-e", ".[dev]")
3625

3726
if session.posargs:
38-
args = session.posargs + ["--all-files"]
27+
args = [*session.posargs, "--all-files"]
3928
else:
4029
args = ["--all-files", "--show-diff-on-failure"]
4130

4231
session.run("pre-commit", "run", *args)
4332
session.run("python", "-m", "mypy")
44-
if sys.version_info >= (3, 11):
45-
return
46-
session.run("python", "-m", "pylint", *locations)
4733

4834

4935
@nox.session

pyproject.toml

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,64 @@
11
[build-system]
2-
requires = ["setuptools>=48", "setuptools_scm[toml]>=6.3.1"]
32
build-backend = "setuptools.build_meta"
3+
requires = [
4+
"setuptools>=48",
5+
"setuptools_scm[toml]>=6.3.1",
6+
]
7+
8+
[project]
9+
name = "pytest-test-utils"
10+
readme = "README.md"
11+
license = { text = "Apache License 2.0" }
12+
authors = [{ name = "Saugat Pachhai", email = "[email protected]" }]
13+
requires-python = ">=3.7"
14+
classifiers = [
15+
"Framework :: Pytest",
16+
"Programming Language :: Python :: 3 :: Only",
17+
"Programming Language :: Python :: 3.7",
18+
"Programming Language :: Python :: 3.8",
19+
"Programming Language :: Python :: 3.9",
20+
"Programming Language :: Python :: 3.10",
21+
"Programming Language :: Python :: 3.11",
22+
"Programming Language :: Python :: 3.12",
23+
]
24+
dynamic = [
25+
"version",
26+
]
27+
dependencies = [
28+
"pytest>=3.9",
29+
]
30+
[project.optional-dependencies]
31+
dev = [
32+
"mypy",
33+
"pytest-test-utils[tests]",
34+
]
35+
tests = [
36+
"coverage>=6",
37+
]
38+
[project.urls]
39+
Issues = "https://github.com/iterative/pytest-test-utils/issues"
40+
Source = "https://github.com/iterative/pytest-test-utils"
41+
[project.entry-points.pytest11]
42+
pytest_test_utils = "pytest_test_utils.pytest_plugin"
43+
44+
[tool.setuptools.package-data]
45+
pytest_test_utils = ["py.typed"]
446

547
[tool.setuptools_scm]
648

7-
[tool.black]
8-
line-length = 79
9-
include = '\.pyi?$'
10-
exclude = '''
11-
/(
12-
\.eggs
13-
| \.git
14-
| \.hg
15-
| \.mypy_cache
16-
| \.tox
17-
| \.venv
18-
| _build
19-
| buck-out
20-
| build
21-
| dist
22-
)/
23-
'''
24-
25-
[tool.isort]
26-
profile = "black"
27-
line_length = 79
49+
[tool.ruff]
50+
output-format = "full"
51+
show-fixes = true
52+
53+
[tool.ruff.lint]
54+
ignore = ["S101"]
55+
extend-select = ["S", "I", "B", "C4", "T10"]
56+
57+
[tool.codespell]
58+
ignore-words-list = "cachable"
59+
60+
[tool.pytest.ini_options]
61+
testpaths = ["tests.py"]
2862

2963
[tool.mypy]
3064
# Error output
@@ -43,13 +77,3 @@ files = ["pytest_test_utils", "tests.py"]
4377
[[tool.mypy.overrides]]
4478
module = ["tests"]
4579
strict_equality = false
46-
47-
[tool.pylint.message_control]
48-
enable = ["no-else-return"]
49-
disable = ["missing-function-docstring", "missing-module-docstring", "missing-class-docstring"]
50-
51-
[tool.pytest.ini_options]
52-
testpaths = ["tests.py"]
53-
54-
[tool.codespell]
55-
ignore-words-list = "cachable"

pytest_test_utils/_approx.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def __init__(
2121
"""Initialize the approx_datetime with `abs` as tolerance."""
2222
assert isinstance(expected, datetime)
2323
abs = abs or self.default_tolerance
24-
assert abs >= timedelta(
25-
0
26-
), f"absolute tolerance can't be negative: {abs}"
24+
assert abs >= timedelta(0), f"absolute tolerance can't be negative: {abs}"
2725
super().__init__(expected, abs=abs)
2826

2927
def __repr__(self) -> str: # pragma: no cover

pytest_test_utils/matchers.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def __init__(
2828
pattern: Union[AnyStr, Pattern[AnyStr]],
2929
flags: Union[int, re.RegexFlag] = 0,
3030
) -> None:
31-
self._regex: Pattern[AnyStr] = re.compile(
32-
pattern, flags # type: ignore[arg-type]
33-
)
31+
self._regex: Pattern[AnyStr] = re.compile(pattern, flags) # type: ignore[arg-type]
3432

3533
def __repr__(self) -> str:
3634
flags = self._regex.flags & ~32 # 32 is default
@@ -63,9 +61,7 @@ class MatcherDict:
6361
# - should not call itself dict or use dict in repr because it creates
6462
# confusing error messages (shadowing python builtins is bad anyway)
6563

66-
def __init__(
67-
self, d: Optional[Mapping[Any, Any]] = None, **keys: Any
68-
) -> None:
64+
def __init__(self, d: Optional[Mapping[Any, Any]] = None, **keys: Any) -> None:
6965
self.d: Dict[Any, Any] = {}
7066
if d:
7167
self.d.update(d)
@@ -112,9 +108,7 @@ def __repr__(self) -> str:
112108
def __eq__(self, other: Any) -> bool:
113109
# Unforturnately this doesn't work with classes with slots
114110
# self.__class__ = other.__class__
115-
return all(
116-
getattr(other, name) == v for name, v in self.attribs.items()
117-
)
111+
return all(getattr(other, name) == v for name, v in self.attribs.items())
118112

119113

120114
class any_of:

pytest_test_utils/tmp_dir_factory.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def __init__(self, tmp_path_factory: "TempPathFactory") -> None:
1111
self.tmp_path_factory: "TempPathFactory" = tmp_path_factory
1212

1313
def mktemp(self, basename: str, numbered: bool = True) -> TmpDir:
14-
return TmpDir(
15-
self.tmp_path_factory.mktemp(basename, numbered=numbered)
16-
)
14+
return TmpDir(self.tmp_path_factory.mktemp(basename, numbered=numbered))
1715

1816
def getbasetemp(self) -> TmpDir:
1917
return TmpDir(self.tmp_path_factory.getbasetemp())

setup.cfg

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def test_gen_dict_bytes(tmp_dir: TmpDir) -> None:
6464
]
6565
assert (tmp_dir / os.fsdecode("file")).read_bytes() == b"lorem"
6666
assert (tmp_dir / os.fsdecode("dir")).is_dir()
67-
assert (
68-
tmp_dir / os.fsdecode("dir") / os.fsdecode("file")
69-
).read_bytes() == b"ipsum"
67+
assert (tmp_dir / os.fsdecode("dir") / os.fsdecode("file")).read_bytes() == b"ipsum"
7068

7169

7270
def test_chdir(tmp_path: Path, tmp_dir: TmpDir) -> None:
@@ -113,13 +111,9 @@ def test_matcher_repr(matcher: Type[Matcher]) -> None:
113111
== "M.dict(foo='foo', n=123)"
114112
)
115113
assert repr(matcher.instance_of(str)) == "instance_of(str)"
116-
assert (
117-
repr(matcher.instance_of((str, bytes))) == "instance_of((str, bytes))"
118-
)
114+
assert repr(matcher.instance_of((str, bytes))) == "instance_of((str, bytes))"
119115
assert repr(matcher.unordered("foo", "bar")) == "unordered('foo', 'bar')"
120-
assert (
121-
repr(matcher.re(r"^plots\.csv-\w+$")) == "regex(r'^plots\\.csv-\\w+$')"
122-
)
116+
assert repr(matcher.re(r"^plots\.csv-\w+$")) == "regex(r'^plots\\.csv-\\w+$')"
123117

124118

125119
def test_matcher_dict(matcher: Type[Matcher]) -> None:
@@ -152,9 +146,7 @@ def test_matcher_attrs(matcher: Type[Matcher]) -> None:
152146

153147

154148
def test_matcher_attrs_nested(matcher: Type[Matcher]) -> None:
155-
obj = SimpleNamespace(
156-
nested=SimpleNamespace(foo="foo", bar="bar"), foobar="bar"
157-
)
149+
obj = SimpleNamespace(nested=SimpleNamespace(foo="foo", bar="bar"), foobar="bar")
158150
assert obj == matcher.attrs(nested=matcher.attrs(foo="foo"))
159151

160152

0 commit comments

Comments
 (0)