Skip to content

Commit 58f0bdb

Browse files
thorsten-kleinpdgendt
authored andcommitted
test local worktree with pytest by default
Enable pytest `pythonpath=src` by default to run tests against the local worktree (e.g. when invoked via `poe test`). An alternative task `poe gh-test` is added, which explicitly unsets `pythonpath` in order to test the installed package (run in CI within `uv` environment).
1 parent de789c8 commit 58f0bdb

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ jobs:
1919
matrix:
2020
os: [ubuntu-latest, macos-latest, windows-latest]
2121
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
22-
task: [test]
22+
task: [gh-test]
2323
# The include map here is actually used to extend the matrix.
2424
# By passing all keys used in the matrix we append new unique combinations.
2525
# For more information see:
2626
# https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#example-adding-configurations
2727
include:
2828
# Run linter/type checks only on 1 combination
29+
- os: ubuntu-latest
30+
python-version: '3.13'
31+
task: test
2932
- os: ubuntu-latest
3033
python-version: '3.13'
3134
task: gh-lint
@@ -61,15 +64,15 @@ jobs:
6164
run: uv run --frozen --directory "./check out/" --env-file=.github/http_env_block.conf poe ${{ matrix.task }}
6265

6366
- name: Upload coverage reports
64-
if: ${{ matrix.task == 'test' }}
67+
if: ${{ matrix.task == 'gh-test' }}
6568
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
6669
with:
6770
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
6871
path: "./check out/.coverage"
6972
include-hidden-files: true
7073

7174
- name: Upload test reports
72-
if: ${{ matrix.task == 'test' }}
75+
if: ${{ matrix.task == 'gh-test' }}
7376
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7477
with:
7578
name: tests-${{ matrix.os }}-${{ matrix.python-version }}

README.rst

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,31 @@ First, install the dependencies::
147147
# Recommended in an active virtual environment
148148
pip3 install --group dev
149149

150-
Then, run the test suite locally from the top level directory::
151150

152-
# Using uv
151+
Then, run the tests (from the project's top level directory)::
152+
153+
# Run the full test suite with uv (recommended)
153154
uv run poe all
154155

155-
# Using poe
156-
# Recommended in an active virtual environment
156+
# Or run the full test suite with poe directly.
157+
# (recommended in an active virtual environment)
157158
poe all
158159

159-
# Manually (test the installed west version)
160+
# Run only the pytest tests (against the local worktree)
160161
pytest
161162

162-
# Manually (test the local copy)
163-
pytest -o pythonpath=src
163+
The ``all`` target from ``poe`` runs multiple tasks sequentially. Use ``poe -h``
164+
to get a list of all available tasks.
165+
You can pass arguments to any ``poe`` task, which are forwarded to the
166+
underlying command. This is especially helpful when you want to run
167+
only specific tests to save time. Examples::
164168

165-
The ``all`` target from ``poe`` runs multiple tasks sequentially. Run ``poe -h``
166-
to get the list of configured tasks.
167-
You can pass arguments to the task running ``poe``. This is especially useful
168-
on specific tests and save time. Examples::
169-
170-
# Run a subset of tests
169+
# Run a subset of tests (file)
171170
poe test tests/test_project.py
172171

172+
# Run a single test
173+
poe test tests/test_project.py::test_workspace
174+
173175
# Run the ``test_update_narrow()`` code with ``pdb`` (but _not_ the
174176
# west code which is running in subprocesses)
175177
poe test --exitfirst --trace -k test_update_narrow

pyproject.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,16 @@ preview = true
110110
mypy_path = "src"
111111
ignore_missing_imports = true
112112

113+
[tool.pytest.ini_options]
114+
# You can override any pytest option via pytest argument `-o key=value`.
115+
# E.g. unset option `-o pythonpath=` to use the installed west in tests
116+
pythonpath = "src"
117+
113118
[tool.poe.tasks.test]
114-
cmd = "python -m pytest -v -W error --junitxml=junit.xml -o junit_family=xunit1 --cov-report=html --cov-config=pyproject.toml --cov=west"
119+
cmd = "python -m pytest -W error"
115120
env = {PYTHONIOENCODING = "utf-8"}
116121

122+
117123
[tool.poe.tasks]
118124
lint = "ruff check ."
119125
format = "ruff format"
@@ -126,3 +132,7 @@ all = ["test", "lint", "format", "types"]
126132
# Github specific tasks
127133
gh-lint = "ruff check --output-format=github ."
128134
gh-format = "ruff format --check --output-format=github"
135+
136+
[tool.poe.tasks.gh-test]
137+
cmd = "python -m pytest -W error -v -o pythonpath= -o junit_family=xunit1 --junitxml=junit.xml --cov-report=html --cov-config=pyproject.toml --cov=west"
138+
env = {PYTHONIOENCODING = "utf-8"}

0 commit comments

Comments
 (0)