Skip to content

Commit 8abc274

Browse files
committed
build: update pyproject.toml to support hatch test command
1 parent b7cc49b commit 8abc274

File tree

17 files changed

+68
-65
lines changed

17 files changed

+68
-65
lines changed

.github/workflows/linters.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ jobs:
8989
- name: Run type check
9090
run: hatch run type-check
9191

92-
- name: Run spell check
93-
run: hatch run spell-check
94-
9592
- name: Run license check
9693
run: hatch run license-check
9794

.github/workflows/release.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ jobs:
3535
shell: bash
3636
run: |
3737
echo "CACHE_KEY=$( \
38-
.github/workflows/get-key.py --hash tool.hatch.envs.default.dependencies \
38+
yq eval -r .tool.hatch.envs.default.dependencies -oy pyproject.toml \
39+
| sha1sum \
40+
| cut -f 1 -d ' ' \
3941
)" | tee -a "${GITHUB_ENV}"
4042
4143
- name: Prepare Cache

.github/workflows/run-tests.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ jobs:
4040

4141
- name: Get Cache Key
4242
run: |
43-
[[ '${{ matrix.python-version }}' == '3.10' ]] && pip install tomli
4443
echo "CACHE_KEY=$( \
45-
.github/workflows/get-key.py --json --hash tool.hatch.envs.test.overrides.matrix.pytest.dependencies \
44+
yq eval -r .tool.hatch.envs.hatch-test.overrides.matrix.pytest.dependencies -oy pyproject.toml \
45+
| sha1sum \
46+
| cut -f 1 -d ' ' \
4647
)" | tee -a "${GITHUB_ENV}"
4748
shell: bash
4849

@@ -58,8 +59,5 @@ jobs:
5859
uses: pypa/hatch@install
5960

6061
- name: Run tests
61-
# NOTE Run tests per environment to avoid `default` environment activation
62-
# when `hatch run test` running.
6362
run: |
64-
hatch run test.pytest.7x:test
65-
hatch run test.pytest.8x:test
63+
hatch test -i pytest=pytest.7x,pytest.8x

ChangeLog.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ to `Semantic Versioning`_.
2626
Unreleased_
2727
===========
2828

29-
Added
30-
-----
29+
Changed
30+
-------
3131

32+
- Set the :option:`pm-patterns-base-dir` default to :file:`tests/data/expected` to align with
33+
the common :file:`tests/` directory layout.
3234
- Improve documentation.
35+
- Update the :file:`pyproject.toml` to suit the :program:`hatch test` command.
3336

3437

3538
2.0.2_ -- 2024-08-01

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SPDX-FileCopyrightText = "2024 Alex Turbov <zaufi@pm.me>"
2525
SPDX-License-Identifier = "CC0-1.0"
2626

2727
[[annotations]]
28-
path = "test/data/**"
28+
path = "tests/data/**"
2929
precedence = "aggregate"
3030
SPDX-FileCopyrightText = "2024 Alex Turbov <zaufi@pm.me>"
3131
SPDX-License-Identifier = "CC0-1.0"

doc/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Marker
6969
def system_specific_test(capfd, expected_out):
7070
...
7171
stdout, _ = capfd.readouterr()
72-
# Get content from `<base-dir>/.../system_specific-Linux.out`
72+
# Get content from `<base-dir>/.../system_specific_test-Linux.out`
7373
assert expected_out == stdout
7474
7575
@pytest.mark.expect_suffix(

doc/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The following options can be set in the `Pytest configuration file`_.
4040

4141
.. option:: pm-patterns-base-dir
4242

43-
:Default: :file:`test/data/expected`
43+
:Default: :file:`tests/data/expected`
4444

4545
Base directory used for storing pattern files.
4646
The directory must be relative to the project's root.

doc/getting-started.rst

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ or with ``diff`` mode highlighted via ``Pygments``:
2121
The plugin provides the fixtures :py:data:`expected_out` and :py:data:`expected_err`.
2222
Usage is straightforward as shown below:
2323

24-
.. literalinclude:: ../test/test_foo.py
24+
.. literalinclude:: ../tests/test_foo.py
2525
:language: python
2626
:pyobject: test_foo
2727

@@ -30,33 +30,34 @@ If you run :command:`pytest` now, the test will be skipped because the expectati
3030
.. code-block:: console
3131
:emphasize-lines: 5,6
3232
33-
$ pytest --no-header --no-summary test/test_foo.py::test_foo
33+
$ pytest --no-header --no-summary tests/test_foo.py::test_foo
3434
============================= test session starts ==============================
3535
collected 1 item
3636
37-
test/test_foo.py::test_foo SKIPPED (Base directory for pattern-matcher
38-
does not exist: `…/pytest-matcher/master/test/data/expected`) [100%]
37+
tests/test_foo.py::test_foo SKIPPED (Base directory for pattern-matcher
38+
does not exist: `…/pytest-matcher/master/tests/data/expected`) [100%]
3939
4040
============================== 1 skipped in 0.01s ==============================
4141
4242
4343
Add the :option:`pm-patterns-base-dir` option to the `Pytest configuration file`_
44-
pointing, for example, to :file:`test/data/expected`. Run :command:`pytest` with
44+
pointing, for example, to :file:`tests/data/expected`. Run :command:`pytest` with
4545
the :option:`--pm-save-patterns` option to write the initial expectation file:
4646

4747
.. code-block:: console
4848
:emphasize-lines: 5,6
4949
50-
$ pytest --pm-save-patterns --no-header --no-summary test/test_foo.py::test_foo
50+
$ pytest --pm-save-patterns --no-header --no-summary tests/test_foo.py::test_foo
5151
============================= test session starts ==============================
5252
collecting ... collected 1 item
5353
54-
test/test_foo.py::test_foo SKIPPED (Pattern file saved to
55-
`…/pytest-matcher/master/test/data/expected/test_foo/test_foo.out`) [100%]
54+
tests/test_foo.py::test_foo SKIPPED (Pattern file saved to
55+
`…/pytest-matcher/master/tests/data/expected/test_foo/test_foo.out`) [100%]
5656
5757
============================== 1 skipped in 0.02s ==============================
5858
59-
Review the stored pattern file :file:`test/data/expected/test_foo/test_foo.out` and add it to your VCS.
59+
Review the stored pattern file :file:`tests/data/expected/test_foo/test_foo.out` and add it to
60+
your VCS.
6061

6162
.. note::
6263

@@ -71,11 +72,11 @@ output matches expectations:
7172
.. code-block:: console
7273
:emphasize-lines: 5
7374
74-
$ pytest --no-header --no-summary test/test_foo.py::test_foo
75+
$ pytest --no-header --no-summary tests/test_foo.py::test_foo
7576
============================= test session starts ==============================
7677
collected 1 item
7778
78-
test/test_foo.py::test_foo PASSED [100%]
79+
tests/test_foo.py::test_foo PASSED [100%]
7980
8081
============================== 1 passed in 0.01s ===============================
8182
@@ -85,20 +86,20 @@ output matches expectations:
8586
If the captured output contains values that change from run to run, for example timestamps
8687
or filesystem paths, you can match the output using regular expressions:
8788

88-
.. literalinclude:: ../test/test_foo.py
89+
.. literalinclude:: ../tests/test_foo.py
8990
:language: python
9091
:pyobject: test_regex
9192

9293
Store the pattern file for this test and rerun :command:`pytest` with the ``-vv`` option:
9394

9495
.. code-block:: console
95-
:emphasize-lines: 24,28
96+
:emphasize-lines: 24,25,28,29
9697
97-
$ pytest -vv --no-header test/test_foo.py::test_regex
98+
$ pytest -vv --no-header tests/test_foo.py::test_regex
9899
============================= test session starts ==============================
99100
collecting ... collected 1 item
100101
101-
test/test_foo.py::test_regex FAILED [100%]
102+
tests/test_foo.py::test_regex FAILED [100%]
102103
103104
=================================== FAILURES ===================================
104105
__________________________________ test_regex __________________________________
@@ -112,43 +113,43 @@ Store the pattern file for this test and rerun :command:`pytest` with the ``-vv`
112113
113114
stdout, _ = capfd.readouterr()
114115
115-
> assert expected_out.match(stdout) ==True
116+
> assert expected_out.match(stdout) == True
116117
E AssertionError: assert
117118
E The test output doesn't match the expected regex.
118-
E (from `…/pytest-matcher/master/test/data/expected/test_foo/test_regex.out`):
119+
E (from `…/pytest-matcher/master/tests/data/expected/test_foo/test_regex.out`):
119120
E ---[BEGIN actual output]---
120121
E Current date: 2024-03-02 21:59:03.792447
121-
E Current module: …/pytest-matcher/master/test/test_foo.py
122+
E Current module: …/pytest-matcher/master/tests/test_foo.py
122123
E ---[END actual output]---
123124
E ---[BEGIN expected regex]---
124125
E Current date: 2024-03-02 21:58:32.289679
125-
E Current module: …/pytest-matcher/master/test/test_foo.py
126+
E Current module: …/pytest-matcher/master/tests/test_foo.py
126127
E ---[END expected regex]---
127128
128-
test/test_foo.py:26: AssertionError
129+
tests/test_foo.py:26: AssertionError
129130
=========================== short test summary info ============================
130-
FAILED test/test_foo.py::test_regex - AssertionError: assert
131+
FAILED tests/test_foo.py::test_regex - AssertionError: assert
131132
============================== 1 failed in 0.03s ===============================
132133
133134
To make it match, edit the expectation file and replace the changing parts with regular
134135
expressions:
135136

136137
.. code-block::
137-
:caption: ``test/data/expect/test_foo/test_regex.out``
138+
:caption: ``tests/data/expect/test_foo/test_regex.out``
138139
139140
Current date: [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?
140-
Current module: .*/test/test_foo.py
141+
Current module: .*/tests/test_foo.py
141142
142143
The test will now pass:
143144

144145
.. code-block:: console
145146
:emphasize-lines: 5
146147
147-
$ pytest --no-header --no-summary test/test_foo.py::test_regex
148+
$ pytest --no-header --no-summary tests/test_foo.py::test_regex
148149
============================= test session starts ==============================
149150
collected 1 item
150151
151-
test/test_foo.py::test_regex PASSED [100%]
152+
tests/test_foo.py::test_regex PASSED [100%]
152153
153154
============================== 1 passed in 0.01s ===============================
154155

pyproject.toml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ packages = ["src/pytest_matcher"]
8787
[tool.hatch.envs.default]
8888
description = "Development environment"
8989
dependencies = [
90-
"codespell >= 2.4.1"
91-
, "isort"
90+
"isort"
9291
, "mypy"
9392
, "reuse ~= 5.0"
9493
, "ruff ~= 0.12.3"
@@ -102,30 +101,28 @@ installer = "uv"
102101
[tool.hatch.envs.default.scripts]
103102
# Some shortcut commands
104103
all = [
105-
"dead-check", "dist-check", "license-check", "lint-check", "pyproject-check", "spell-check", "type-check"
104+
"dead-check", "dist-check", "license-check", "lint-check", "pyproject-check", "type-check"
106105
]
107106
# Various linter commands
108107
dead-check = "vulture src/pytest_matcher"
109108
dist-check = "twine check dist/*"
110109
license-check = "reuse lint"
111-
lint-check = "ruff check doc src/pytest_matcher test"
110+
lint-check = "ruff check doc src/pytest_matcher tests"
112111
pyproject-check = "validate-pyproject {root:real}/pyproject.toml"
113-
spell-check = "codespell"
114-
type-check = "mypy src/pytest_matcher test"
115-
# Testing commands
116-
cov = "hatch env run -e test cov"
117-
test = "hatch env run -e test test"
112+
type-check = "mypy src/pytest_matcher"
113+
# Testing shortcut commands
114+
cov = "hatch test --cov"
115+
test = "hatch test -i pytest=pytest.7x,pytest.8x"
118116
# Misc commands
119117
annotate-code = "reuse annotate -c \"$(git config --get user.name) <$(git config --get user.email)>\" -t code -l GPL-3.0-or-later {args}"
120118
annotate-misc = "reuse annotate -c \"$(git config --get user.name) <$(git config --get user.email)>\" -t misc -l CC0-1.0 {args}"
121119
dist = "hatch build -t wheel"
122-
fix-spelling = "codespell -i 3 -w"
123120

124121
[tool.hatch.envs.doc]
125122
description = "Environment to build documentation"
126123
dependencies = [
127-
"sphinx < 8.0.0"
128-
, "sphinx_rtd_theme >= 2.0.0"
124+
"sphinx"
125+
, "sphinx_rtd_theme"
129126
]
130127
installer = "uv"
131128
template = "doc"
@@ -135,26 +132,31 @@ build = "sphinx-build --color -j auto doc/ build/sphinx/html/"
135132
link-check = "sphinx-build --color -b linkcheck doc/ build/sphinx/link-check/"
136133
show = "xdg-open build/sphinx/html/index.html"
137134

138-
[tool.hatch.envs.test]
135+
[tool.hatch.envs.hatch-test]
139136
description = "Unit tests environment"
140-
template = "test"
137+
dependencies = [
138+
"coverage-enable-subprocess == 1.0",
139+
"coverage[toml] ~= 7.4",
140+
"pytest-randomly ~= 3.15",
141+
"pytest-rerunfailures ~= 14.0",
142+
"pytest-xdist[psutil] ~= 3.5",
143+
]
141144
installer = "uv"
142145

143-
[[tool.hatch.envs.test.matrix]]
146+
[[tool.hatch.envs.hatch-test.matrix]]
144147
pytest = ["pytest.8x", "pytest.7x"]
145148

146-
[tool.hatch.envs.test.overrides]
149+
[tool.hatch.envs.hatch-test.overrides]
147150
matrix.pytest.dependencies = [
148151
"coverage[toml]"
149152
, "pytest-cov"
150153
, { value = "pytest ~= 8.0", if = ["pytest.8x"] }
151154
, { value = "pytest ~= 7.0", if = ["pytest.7x"] }
152155
]
153156

154-
[tool.hatch.envs.test.scripts]
157+
[tool.hatch.envs.hatch-test.scripts]
158+
run = "pytest{env:HATCH_TEST_ARGS:} -o cache_dir=build/.{matrix:pytest}_cache {verbosity:flag} {args}"
155159
cov = "pytest --cov-report term --cov-report html:build/coverage-{matrix:pytest} --cov=pytest_matcher"
156-
show-cov = "xdg-open build/coverage-{matrix:pytest}/index.html"
157-
test = "pytest -o cache_dir=build/.{matrix:pytest}_cache {verbosity:flag} {args}"
158160

159161
[tool.hatch.version]
160162
source = "vcs"
@@ -229,7 +231,7 @@ minversion = "7.0"
229231
python_files = ["test_*.py"]
230232
python_classes = ["*Tester"]
231233
python_functions = ["*_test", "*_test_?", "*_test_??", "test_*"]
232-
testpaths = ["test"]
234+
testpaths = ["tests"]
233235
xfail_strict = true
234236

235237
# https://docs.astral.sh/ruff/configuration/
@@ -256,12 +258,12 @@ select = ["ALL"]
256258
, "D100" # Missing docstring in public module
257259
, "A001" # Variable `copyright` is shadowing a Python builtin
258260
]
259-
"test/test_*.py" = [
261+
"tests/test_*.py" = [
260262
"ANN001" # Missing type annotation for function argument
261263
, "D" # Documentation issues
262264
, "PLR2004" # Magic value used in comparison
263265
]
264-
"test/test_foo.py" = [
266+
"tests/test_foo.py" = [
265267
"T201" # `print` found
266268
, "E712" # Comparison to `True`
267269
, "DTZ005" # The use of `datetime.datetime.now()` without `tz` argument is not allowed

src/pytest_matcher/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
469469
parser.addini(
470470
'pm-patterns-base-dir'
471471
, help='Base directory used for storing pattern files.'
472-
, default=pathlib.Path('test/data/expected')
472+
, default=pathlib.Path('tests/data/expected')
473473
)
474474
parser.addini(
475475
'pm-pattern-file-fmt'

0 commit comments

Comments
 (0)